Skip to content

Instantly share code, notes, and snippets.

@krishnabhargav
Created January 25, 2015 16:30
Show Gist options
  • Save krishnabhargav/6a1571427f4e08b901de to your computer and use it in GitHub Desktop.
Save krishnabhargav/6a1571427f4e08b901de to your computer and use it in GitHub Desktop.
type inference in F# starts from left to right and top to bottom. So if you do not use |> operator, then type annotations in lambda expression will be required.
let sizeOfFolder folder =
let allFiles = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
let fileInfos = allFiles |> Array.map (fun x -> new FileInfo(x))
let allSizes = fileInfos |> Array.map (fun x -> x.Length)
Array.sum allSizes
///This version requires explicit type annotations in the lambda
let sizeOfFolder2 folder =
let allFiles = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
let fileInfos = Array.map (fun (x:string) -> new FileInfo(x)) allFiles
let allSizes = Array.map (fun (x:FileInfo) -> x.Length) fileInfos
Array.sum allSizes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment