Skip to content

Instantly share code, notes, and snippets.

@jackmott
Last active September 1, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmott/49a77953544458a14e4c2088047e9c71 to your computer and use it in GitHub Desktop.
Save jackmott/49a77953544458a14e4c2088047e9c71 to your computer and use it in GitHub Desktop.
Example of poly_inc map combo in Fsharp
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