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 with, contrast, partial, function and/or application:

    By contrast with history, evolution is an unconscious process. Another, and perhaps a better way of putting it would be to say that evolution is a natural process, history a human one.... Insofar as we treat man as a part of nature—for instance in a biological survey of evolution—we are precisely not treating him as a historical being. As a historically developing being, he is set over against nature, both as a knower and as a doer.
    Owen Barfield (b. 1898)

    In contrast to the flux and muddle of life, art is clarity and enduring presence. In the stream of life, few things are perceived clearly because few things stay put. Every mood or emotion is mixed or diluted by contrary and extraneous elements. The clarity of art—the precise evocation of mood in the novel, or of summer twilight in a painting—is like waking to a bright landscape after a long fitful slumber, or the fragrance of chicken soup after a week of head cold.
    Yi-Fu Tuan (b. 1930)

    There is no luck in literary reputation. They who make up the final verdict upon every book are not the partial and noisy readers of the hour when it appears; but a court as of angels, a public not to be bribed, not to be entreated, and not to be overawed, decides upon every man’s title to fame. Only those books come down which deserve to last.
    Ralph Waldo Emerson (1803–1882)

    Of all the inhabitants of the inferno, none but Lucifer knows that hell is hell, and the secret function of purgatory is to make of heaven an effective reality.
    Arnold Bennett (1867–1931)

    It is known that Whistler when asked how long it took him to paint one of his “nocturnes” answered: “All of my life.” With the same rigor he could have said that all of the centuries that preceded the moment when he painted were necessary. From that correct application of the law of causality it follows that the slightest event presupposes the inconceivable universe and, conversely, that the universe needs even the slightest of events.
    Jorge Luis Borges (1899–1986)