Last active
September 1, 2016 20:32
-
-
Save jackmott/49a77953544458a14e4c2088047e9c71 to your computer and use it in GitHub Desktop.
Example of poly_inc map combo in Fsharp
This file contains 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 inline map (array : 'T[]) f : 'U[] = | |
let result = Array.zeroCreate array.Length | |
for i = 0 to array.Length-1 do | |
result.[i] <- f array.[i] | |
result | |
let inline poly_incr x = | |
x + LanguagePrimitives.GenericOne | |
[<EntryPoint>] | |
let main argv = | |
let intArray = [|1;2;3;4|] | |
let floatArray = [|1.0;2.0;3.0;4.0|] | |
let result1 = map intArray poly_incr | |
let result2 = map floatArray poly_incr | |
0 | |
//Alternate syntax | |
let inline map2 (array : 'T[]) f : 'U[] = | |
[| for i = 0 to array.Length-1 do yield f array.[i] |] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment