Currying - Motivation

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:

To evaluate f(2,3), first replace x with 2.
Since the result is a function of y, this function g(y) can be defined as g(y) = f(2,y) = y/2.
Next, replace the y argument with 3, producing g(3) = f(2,3) = 3/2.

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 multi-argument 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.

If we let f be a function

then the function h where

is a curried version of . Here, is a function that maps an argument y to result z. In particular,

is the curried equivalent of the example above. Note, however, that currying, while similar, is not the same operation as partial function application.

Read more about this topic:  Currying

Famous quotes containing the word motivation:

    Self-determination has to mean that the leader is your individual gut, and heart, and mind or we’re talking about power, again, and its rather well-known impurities. Who is really going to care whether you live or die and who is going to know the most intimate motivation for your laughter and your tears is the only person to be trusted to speak for you and to decide what you will or will not do.
    June Jordan (b. 1939)