45 people like it.

Curry / Uncurry

Helpers to convert functions that take a 2-tuple to curried functions and vice versa. Very helpfull for the "Zip"-functor together with operators - see example

1: 
2: 
3: 
4: 
let curry f a b = f (a,b)
let uncurry f (a,b) = f a b

let ArrayMultiply a b = Array.zip a b |> Array.map (uncurry (*))
val curry : f:('a * 'b -> 'c) -> a:'a -> b:'b -> 'c

Full name: Script.curry
val f : ('a * 'b -> 'c)
val a : 'a
val b : 'b
val uncurry : f:('a -> 'b -> 'c) -> a:'a * b:'b -> 'c

Full name: Script.uncurry
val f : ('a -> 'b -> 'c)
val ArrayMultiply : a:int [] -> b:int [] -> int []

Full name: Script.ArrayMultiply
val a : int []
val b : int []
module Array

from Microsoft.FSharp.Collections
val zip : array1:'T1 [] -> array2:'T2 [] -> ('T1 * 'T2) []

Full name: Microsoft.FSharp.Collections.Array.zip
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []

Full name: Microsoft.FSharp.Collections.Array.map
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/3n
Posted:13 years ago
Author:Carsten König
Tags: composition , currying