Currying
Currying is a technique, named after Haskell B. Curry, whereby a function taking multiple parameters may be expressed in terms of functions taking only a single parameter. The key idea behind currying is that, using nested function definitions, multiple parameters may be given to function by binding exactly one parameter at each nesting level; at the innermost nesting level, all of the parameters to the original function have been bound, and the definition of the original function may be given at this innermost level. To make this more concrete, consider the following function in a JavaScript-like syntax:
var f = function(x,y,z) { return x+y+z; } var s = f(1,2,3);
Using the technique of currying, this can be rewritten as:
var f = function(x) { var g = function(y) { var h = function(z) { return x+y+z; } return h; } return g; } var s = ((f(1))(2))(3);
Uses
Currying is a powerful idea in that it essentially shows that, in the presence of nested functions, one can support only one parameter per function without limiting the language's expressive ability. In other words, currying shows that parameter lists with more than one parameter are really nothing more than syntactic sugar. This is incredibly useful when bootstrapping a programming language, since we would like to make it easy to implement the kernel of the programming language while not sacrificing too much functionality; with currying, the kernel of the programming language does not need to support multiple-parameter functions in order for the programming language implemented on top of it to provide them.