Currying - Contrast With Partial Function Application

Contrast With Partial Function Application

Currying and partial function application are often conflated. The difference between the two is clearest for functions taking more than two arguments.

Given a function of type, currying produces . That is, while an evaluation of the first function might be represented as, evaluation of the curried function would be represented as, applying each argument in turn to a single-argument function returned by the previous invocation. Note that after calling, we are left with a function that takes a single argument and returns another function, not a function that takes two arguments.

In contrast, partial function application refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Given the definition of above, we might fix (or 'bind') the first argument, producing a function of type . Evaluation of this function might be represented as . Note that the result of partial function application in this case is a function that takes two arguments.

Intuitively, partial function application says "if you fix the first arguments of the function, you get a function of the remaining arguments". For example, if function div stands for the division operation x/y, then div with the parameter x fixed at 1 (i.e., div 1) is another function: the same as the function inv that returns the multiplicative inverse of its argument, defined by inv(y) = 1/y.

The practical motivation for partial application is that very often the functions obtained by supplying some but not all of the arguments to a function are useful; for example, many languages have a function or operator similar to plus_one. Partial application makes it easy to define these functions, for example by creating a function that represents the addition operator with 1 bound as its first argument.

Read more about this topic:  Currying

Famous quotes containing the words contrast, partial, function and/or application:

    In contrast with envy, which usually occurs between two people and is focused upon another person’s qualities or possessions, jealousy occurs when a third person becomes a threat to a dyad. Jealousy involves the loss or the impending loss of a relationship that one wants to hold onto, a relationship that is vital to personal fulfillment and claimed as one’s own.
    Carol S. Becker (b. 1942)

    The one-eyed man will be King in the country of the blind only if he arrives there in full possession of his partial faculties—that is, providing he is perfectly aware of the precise nature of sight and does not confuse it with second sight ... nor with madness.
    Angela Carter (1940–1992)

    The function of literature, through all its mutations, has been to make us aware of the particularity of selves, and the high authority of the self in its quarrel with its society and its culture. Literature is in that sense subversive.
    Lionel Trilling (1905–1975)

    Preaching is the expression of the moral sentiment in application to the duties of life.
    Ralph Waldo Emerson (1803–1882)