43 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: 
5: 
6: 
7: 
let curry f a b = f (a,b)
let uncurry f (a,b) = f a b

let inline ZipMap f a b = Seq.zip a b |> Seq.map (uncurry f)
let inline seqMult a b = ZipMap (*) a b

seqMult [1.0; 2.0; 3.5] [2.0; 3.1; 4.0]
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 ZipMap : f:('a -> 'b -> 'c) -> a:seq<'a> -> b:seq<'b> -> seq<'c>

Full name: Script.ZipMap
val a : seq<'a>
val b : seq<'b>
module Seq

from Microsoft.FSharp.Collections
val zip : source1:seq<'T1> -> source2:seq<'T2> -> seq<'T1 * 'T2>

Full name: Microsoft.FSharp.Collections.Seq.zip
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val seqMult : a:seq<'a> -> b:seq<'b> -> seq<'c> (requires member ( * ))

Full name: Script.seqMult
val a : seq<'a> (requires member ( * ))
val b : seq<'b> (requires member ( * ))

More information

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