Created
January 25, 2015 16:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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