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!
{{short description|Transforming a function in such a way that it only takes a single argument}} {{about|the mathematical technique|the cooking process of this name|Curry|the leather finishing process|Currier|horse grooming|Currycomb}} In [[mathematics]] and [[computer science]], '''currying''' is the technique of translating a [[Function (mathematics)|function]] that takes multiple [[Parameter (computer science)|arguments]] into a sequence of families of functions, each taking a single argument. In the prototypical example, one begins with a function <math>f:(X\times Y)\to Z</math> that takes two arguments, one from <math>X</math> and one from <math>Y,</math> and produces objects in <math>Z.</math> The curried form of this function treats the first argument as a parameter, so as to create a family of functions <math>f_x :Y\to Z.</math> The family is arranged so that for each object <math>x</math> in <math>X,</math> there is exactly one function <math>f_x.</math> In this example, <math>\mbox{curry}</math> itself becomes a function, that takes <math>f</math> as an argument, and returns a function that maps each <math>x</math> to <math>f_x.</math> The proper notation for expressing this is verbose. The function <math>f</math> belongs to the set of functions <math>(X\times Y)\to Z.</math> Meanwhile, <math>f_x</math> belongs to the set of functions <math>Y\to Z.</math> Thus, something that maps <math>x</math> to <math>f_x</math> will be of the type <math>X\to [Y\to Z].</math> With this notation, <math>\mbox{curry}</math> is a function that takes objects from the first set, and returns objects in the second set, and so one writes <math>\mbox{curry}:[(X\times Y)\to Z]\to (X\to [Y\to Z]).</math> This is a somewhat informal example; more precise definitions of what is meant by "object" and "function" are given below. These definitions vary from context to context, and take different forms, depending on the theory that one is working in. Currying is related to, but not the same as, [[partial application]].<ref name="lambda-the-ultimate">{{Cite web |last=cdiggins |date=24 May 2007 |title=Currying != Generalized Partial Application?! |url=http://lambda-the-ultimate.org/node/2266 |access-date= |website=Lambda the Ultimate: The Programming Languages Weblog}}</ref><ref name="uncarved"/> The example above can be used to illustrate partial application; it is quite similar. Partial application is the function <math>\mbox{apply}</math> that takes the pair <math>f</math> and <math>x</math> together as arguments, and returns <math>f_x.</math> Using the same notation as above, partial application has the signature <math>\mbox{apply}:([(X\times Y)\to Z] \times X) \to [Y\to Z].</math> Written this way, application can be seen to be adjoint to currying. The currying of a function with more than two arguments can be defined by induction. Currying is useful in both practical and theoretical settings. In [[functional programming]] [[Programming language|languages]], and many others, it provides a way of automatically managing how arguments are passed to functions and exceptions. In [[theoretical computer science]], it provides a way to study functions with multiple arguments in simpler theoretical models which provide only one argument. The most general setting for the strict notion of currying and uncurrying is in the [[closed monoidal category|closed monoidal categories]], which underpins a vast generalization of the [[Curry–Howard correspondence]] of proofs and programs to a correspondence with many other structures, including quantum mechanics, cobordisms and string theory.<ref name="rosetta"/> The concept of currying was introduced by [[Gottlob Frege]],<ref name="Frege">{{Cite book |last=Frege |first=Gottlob |url=http://archive.org/details/bub_gb_LZ5tAAAAMAAJ |title=Grundgesetze der arithmetik |publisher=Hermann Pohle |others=Book from the collections of University of Wisconsin - Madison, digitized by Google on 26 August 2008 |year=1893 |publication-place=Jena |pages=54–55 |language=de |chapter=§ 36 |author-link=Gottlob Frege |chapter-url=https://archive.org/details/bub_gb_LZ5tAAAAMAAJ/page/n89}}</ref><ref name="quine">{{Cite book |last=Quine |first=W. V. |title=From Frege to Gödel: A Source Book in Mathematical Logic, 1879-1931 |publisher=Harvard University Press |year=1967 |isbn=9780674324497 |editor-last=van Heijenoort |editor-first=Jean |pages=355–357 |chapter=Introduction to Moses Schönfinkel's 1924 "On the building blocks of mathematical logic" |author-link=Willard Van Orman Quine}}</ref> developed by [[Moses Schönfinkel]],<ref>{{cite journal |last1=Schönfinkel |first1=Moses |author1-link=Moses Schönfinkel |date=September 1924 |orig-date=Presented at the Mathematischen Gesellschaft (Mathematical Society) in Göttingen on 7 December 1920. Received by Mathematische Annalen on 15 March 1924. |title=Über die Bausteine der mathematischen Logik |trans-title=On the building blocks of mathematical logic |url=http://www.cip.ifi.lmu.de/~langeh/test/1924%20-%20Schoenfinkel%20-%20Ueber%20die%20Bausteine%20der%20mathematischen%20Logik.pdf |journal=[[Mathematische Annalen]] |location=Moskau |publisher=Springer |publication-place=Berlin? |volume=92 |issue=3–4 |pages=305–316 |doi=10.1007/BF01448013 |s2cid=118507515}}</ref><ref name="quine"/><ref name="Strachey">{{Cite journal |last1=Strachey |first1=Christopher |author1-link=Christopher Strachey |date=April 2000 |orig-date=This paper forms the substance of a course of lectures given at the International Summer School in Computer Programming at Copenhagen in August, 1967. |title=Fundamental Concepts in Programming Languages |url=https://doi.org/10.1023/A:1010000313106 |journal=Higher-Order and Symbolic Computation |language=en |volume=13 |issue= |pages=11–49 |citeseerx=10.1.1.332.3161 |doi=10.1023/A:1010000313106 |issn=1573-0557 |s2cid=14124601 |quote=There is a device originated by Schönfinkel, for reducing operators with several operands to the successive application of single operand operators.}}</ref><ref name="Reynolds">Originally published as {{Cite book |last1=Reynolds |first1=John C. |author1-link=John C. Reynolds |chapter=Definitional interpreters for higher-order programming languages |editor1-last=Shields |editor1-first=Rosemary |title=Proceedings of the ACM annual conference - ACM '72 |date=1 August 1972 |chapter-url=http://portal.acm.org/citation.cfm?doid=800194.805852 |language=en |publisher=ACM Press |volume=2 |pages=717–740 |doi=10.1145/800194.805852 |isbn=9781450374927 |s2cid=163294 |url=https://surface.syr.edu/lcsmith_other/13 |quote=In the last line we have used a trick called Currying (after the logician H. Curry) to solve the problem of introducing a binary operation into a language where all functions must accept a single argument. (The referee comments that although "Currying" is tastier, "Schönfinkeling” might be more accurate.)}} Republished as {{Cite journal |last1=Reynolds |first1=John C. |author1-link=John C. Reynolds |date=1998 |title=Definitional Interpreters for Higher-Order Programming Languages |url=https://surface.syr.edu/cgi/viewcontent.cgi?article=1012&context=lcsmith_other |journal=Higher-Order and Symbolic Computation |publisher=Kluwer Academic Publishers |publication-place=Boston |volume=11 |issue=4 |pages=363–397 |doi=10.1023/A:1010027404223 |id=13 |via=Syracuse University: College of Engineering and Computer Science - Former Departments, Centers, Institutes and Projects}}</ref><ref>{{Cite book |last1=Slonneger |first1=Kenneth |last2=Kurtz |first2=Barry L. |year=1995 |url=https://cdn.preterhuman.net/texts/science_and_technology/artificial_intelligence/Formal%20Syntax%20and%20Semantics%20of%20Programming%20Languages%20-%20Kenneth%20Slonneger.pdf#page=161 |title=Formal Syntax and Semantics of Programming Languages: A Laboratory Based Approach |publisher=Addison-Wesley Publishing Company |isbn=0-201-65697-3 |page=144 |chapter=Curried Functions, 5.1: Concepts and Examples, Chapter 5: The Lambda Calculus}}</ref><ref name="haskell"/><ref>{{Cite web |date=6 May 2012 |title=Currying Schonfinkelling |url=http://wiki.c2.com/?CurryingSchonfinkelling |access-date= |website=[[Portland Pattern Repository]] Wiki |publisher=Cunningham & Cunningham, Inc.}}</ref> and further developed by [[Haskell Curry]].<ref name="Reynolds"/><ref name="haskell"/><ref>{{Cite book |last1=Barendregt |first1=Henk |url=https://www.cse.chalmers.se/research/group/logic/TypesSS05/Extra/geuvers.pdf |title=Introduction to Lambda Calculus |last2=Barendsen |first2=Erik |date=March 2000 |edition=Revised |page=8 |orig-date=December 1998}}</ref><ref>{{cite book |last1=Curry |first1=Haskell |author1-link=Haskell Curry |last2=Feys |first2=Robert |title=Combinatory logic |publisher=North-Holland Publishing Company |volume=I |edition=2 |year=1958 |location=Amsterdam, Netherlands}}</ref> '''Uncurrying''' is the [[Duality (mathematics)|dual]] transformation to currying, and can be seen as a form of [[defunctionalization]]. It takes a [[function (mathematics)|function]] <math>f</math> whose return value is another function <math>g</math>, and yields a new function <math>f'</math> that takes as parameters the arguments for both <math>f</math> and <math>g</math>, and returns, as a result, the application of <math>f</math> and subsequently, <math>g</math>, to those arguments. The process can be iterated.
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)