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:
“Flowers and fruits are always fit presents; flowers, because they are a proud assertion that a ray of beauty outvalues all of the utilities of the world. These gay natures contrast with the somewhat stern countenance of ordinary nature: they are like music heard out of a work-house.”
—Ralph Waldo Emerson (18031882)
“Armies, for the most part, are made up of men drawn from simple and peaceful lives. In time of war they suddenly find themselves living under conditions of violence, requiring new rules of conduct that are in direct contrast to the conditions they lived under as civilians. They learn to accept this to perform their duties as fighting men.”
—Gil Doud, U.S. screenwriter, and Jesse Hibbs. Walter Bedell Smith (Himself)
“The only coöperation which is commonly possible is exceedingly partial and superficial; and what little true coöperation there is, is as if it were not, being a harmony inaudible to men. If a man has faith, he will coöperate with equal faith everywhere; if he has not faith, he will continue to live like the rest of the world, whatever company he is joined to.”
—Henry David Thoreau (18171862)
“It is the function of vice to keep virtue within reasonable bounds.”
—Samuel Butler (18351902)
“Great abilites are not requisite for an Historian; for in historical composition, all the greatest powers of the human mind are quiescent. He has facts ready to his hand; so there is no exercise of invention. Imagination is not required in any degree; only about as much as is used in the lowest kinds of poetry. Some penetration, accuracy, and colouring, will fit a man for the task, if he can give the application which is necessary.”
—Samuel Johnson (17091784)