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:

    Happiness ain’t a thing in itself—it’s only a contrast with something that ain’t pleasant.... And so, as soon as the novelty is over and the force of the contrast dulled, it ain’t happiness any longer, and you have to get something fresh.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)

    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)

    We were soon in the smooth water of the Quakish Lake,... and we had our first, but a partial view of Ktaadn, its summit veiled in clouds, like a dark isthmus in that quarter, connecting the heavens with the earth.
    Henry David Thoreau (1817–1862)

    “... The state’s one function is to give.
    The bud must bloom till blowsy blown
    Its petals loosen and are strown;
    And that’s a fate it can’t evade
    Unless ‘twould rather wilt than fade.”
    Robert Frost (1874–1963)

    By an application of the theory of relativity to the taste of readers, to-day in Germany I am called a German man of science, and in England I am represented as a Swiss Jew. If I come to be regarded as a bĂȘte noire the descriptions will be reversed, and I shall become a Swiss Jew for the Germans and a German man of science for the English!
    Albert Einstein (1879–1955)