In mathematics and computer science, currying is the technique of transforming a function that takes multiple arguments (or an ntuple of arguments) in such a way that it can be called as a chain of functions each with a single argument. It was invented by Moses SchÃ¶nfinkel and later reinvented by Haskell Curry,^{[1]}^{[not specific enough to verify]}
Uncurrying is the dual transformation to currying, and can be seen as a form of defunctionalization. It takes a function f(x) which returns another function g(y) as a result, and yields a new function f'(x, y) which takes a number of additional parameters and applies them to the function returned by f. The process can be iterated if necessary.
Contents
Motivation
Currying is similar to the process of calculating a function of multiple variables for some given values on paper. For example, given the function f(x,y) = y / x:
On paper, using classical notation, this is usually done all in one step. However, each argument can be replaced sequentially as well. Each replacement results in a function taking exactly one argument. This produces a chain of functions as in lambda calculus, and multiargument functions are usually represented in curried form.
Some programming languages almost always use curried functions to achieve multiple arguments; notable examples are ML and Haskell, where in both cases all functions have exactly one argument.
This is similar in computer code: If we let f be a function f(x,y) = y / x, then the function is a curried version of f. In particular, is the curried equivalent of the example above. Though note that currying, while similar, is not the same operation as partial function application.
Full article ▸
