wiki:FirstPrinciples/Currying

Currying

Currying is a particular pattern of nesting of function calls, such that more than one argument could be supplied to a function.

The related notion is Partial Application, when a curried function is applied to a fewer actual argument values.

In Haskell and Standard ML currying is implicit - each function has exactly one argument. No more, no less. All multi argument functions are syntactic sugar, which expands to application of curried procedures.

f x y = \x -> \y -> (f x) y

Generalizing currying

fun curry f = fn x => fn y => f (x,y)

or using the special syntax

fun curry f x y = f (x,y)

and the dual

fun uncurry f = fn (x,y) => (f x) y

or just

fun uncurry f (x,y) = f x y

which itself is a curried function, which takes f and a pattern - a tuple (x,y)

currying on the second argument (instead of the first)

fun curry1 f = fn x => fn y => f y x

or

fun cirry1 f x y = f y x

Example


See also [Partial Application]

Last modified 2 years ago Last modified on Nov 15, 2018, 10:14:45 AM
Note: See TracWiki for help on using the wiki.