Jul 5, 2011

f# essential - part 7 Curry

Function application, also sometimes referred to as function composition or composing functions is a big thing in functional programming. One style of composition is called Curry. Curry is feature of lots functional language. When you have a function with two parameter, you can pass one argument to the function, that create an new partial function, which accept one parameter. This partial function is also called curried function. F# support this in a very elegant syntax.

let print x y = 
     printfn "%i" x 
     printfn "%s" y 
let print100y = print 100 //create a curried function 
print100y "hello" //call the curried function 

If you want to fill in the second argument to create a new function, this is also support, like below.

let printx_hello x = dosomething x "hello" 
printx_hello 100