Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Currying
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Contrast with partial function application == {{main article|Partial application}} Currying and partial function application are often conflated.<ref name="lambda-the-ultimate" /><ref name="uncarved">{{cite web |date=7 August 2020 |title=Partial Function Application is not Currying |url=https://www.uncarved.com/articles/not-currying/ |url-status=live |archive-url=https://web.archive.org/web/20161023205431/http://www.uncarved.com/articles/not_currying |archive-date=23 October 2016 |work=The Uncarved Block}}</ref> One of the significant differences between the two is that a call to a partially applied function returns the result right away, not another function down the currying chain; this distinction can be illustrated clearly for functions whose [[arity]] is greater than two.<ref>{{cite web |last=Lee |first=G. Kay |date=15 May 2013 |title=Functional Programming in 5 Minutes |url=http://slid.es/gsklee/functional-programming-in-5-minutes |work=Slides}}</ref> Given a function of type <math>f \colon (X \times Y \times Z) \to N </math>, currying produces <math>\text{curry}(f) \colon X \to (Y \to (Z \to N)) </math>. That is, while an evaluation of the first function might be represented as <math>f(1, 2, 3)</math>, evaluation of the curried function would be represented as <math>f_\text{curried}(1)(2)(3)</math>, applying each argument in turn to a single-argument function returned by the previous invocation. Note that after calling <math>f_\text{curried}(1)</math>, 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 <math>f</math> above, we might fix (or 'bind') the first argument, producing a function of type <math>\text{partial}(f) \colon (Y \times Z) \to N</math>. Evaluation of this function might be represented as <math>f_\text{partial}(2, 3)</math>. 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 [[parameter (computer science)|argument]] 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 <code>plus_one</code>. 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. Partial application can be seen as evaluating a curried function at a fixed point, e.g. given <math>f \colon (X \times Y \times Z) \to N </math> and <math>a \in X</math> then <math>\text{curry}(\text{partial}(f)_a)(y)(z) = \text{curry}(f)(a)(y)(z) </math> or simply <math>\text{partial}(f)_a = \text{curry}_1(f)(a) </math> where <math>\text{curry}_1</math> curries f's first parameter. Thus, partial application is reduced to a curried function at a fixed point. Further, a curried function at a fixed point is (trivially), a partial application. For further evidence, note that, given any function <math>f(x,y)</math>, a function <math>g(y,x)</math> may be defined such that <math>g(y,x) = f(x,y)</math>. Thus, any partial application may be reduced to a single curry operation. As such, curry is more suitably defined as an operation which, in many theoretical cases, is often applied recursively, but which is theoretically indistinguishable (when considered as an operation) from a partial application. So, a partial application can be defined as the objective result of a single application of the curry operator on some ordering of the inputs of some function.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)