e01.org

Currying

In mathematics and computer science, currying (named after Haskell Curry) is the technique of translating a function that takes multiple arguments into a sequence of families of functions, each taking a single argument. In the prototypical example, one begins with a function f:(X\times Y)\to Z that takes two arguments, one from X and one from Y, and produces objects in Z. The curried form of this function treats the first argument as a parameter, so as to create a family of functions f_x :Y\to Z. The family is arranged so that for each object x in X, there is exactly one function f_x , such that for any y in Y , f_x(y) = f(x,y) . In this example, \mbox{curry} itself becomes a function that takes f as an argument, and returns a function that maps each x to f_x. The proper notation for expressing this is verbose. The function f belongs to the set of functions (X\times Y)\to Z. Meanwhile, f_x belongs to the set of functions Y\to Z. Thus, something that maps x to f_x will be of the...

In mathematics and computer science, currying (named after Haskell Curry) is the technique of translating a function that takes multiple arguments into a sequence of families of functions, each taking a single argument. In the prototypical example, one begins with a function f:(X\times Y)\to Z that takes two arguments, one from X and one from Y, and produces objects in Z. The curried form of this function treats the first argument as a parameter, so as to create a family of functions f_x :Y\to Z. The family is arranged so that for each object x in X, there is exactly one function f_x , such that for any y in Y , f_x(y) = f(x,y) . In this example, \mbox{curry} itself becomes a function that takes f as an argument, and returns a function that maps each x to f_x. The proper notation for expressing this is verbose. The function f belongs to the set of functions (X\times Y)\to Z. Meanwhile, f_x belongs to the set of functions Y\to Z. Thus, something that maps x to f_x will be of the type X\to [Y\to Z]. With this notation, \mbox{curry} is a function that takes objects from the first set, and returns objects in the second set, and so one writes \mbox{curry}:[(X\times Y)\to Z]\to (X\to [Y\to Z]). 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. The example above can be used to illustrate partial application; it is quite similar. Partial application is the function \mbox{apply} that takes the pair f and x together as arguments, and returns f_x. Using the same notation as above, partial application has the signature \mbox{apply}:([(X\times Y)\to Z] \times X) \to [Y\to Z]. 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 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 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. The concept of currying was introduced by Gottlob Frege, developed by Moses Schönfinkel, and further developed by Haskell Curry. Uncurrying is the dual transformation to currying, and can be seen as a form of defunctionalization. It takes a function f whose return value is another function g , and yields a new function f' that takes as parameters the arguments for both f and g , and returns, as a result, the application of f and subsequently, g , to those arguments. The process can be iterated. f \colon (X \times Y) \to Z , currying constructs a new function g \colon X \to (Y \to Z) . That is, g takes an argument of type X and returns a function of type Y\to Z . It is defined by g(x)(y)=f(x,y) for x of type X and y of type Y . We then also write \text{curry}(f)=g. Uncurrying is the reverse transformation, and is most easily understood in terms of its right adjoint, the function \operatorname{apply}. A^{B\times C}\cong (A^C)^B Indeed, it is this natural bijection that justifies the exponential notation for the set of functions. As is the case in all instances of currying, the formula above describes an adjoint pair of functors: for every fixed set C , the functor B\mapsto B\times C is left adjoint to the functor A \mapsto A^C . In the category of sets, the object Y^X is called the exponential object. \text{curry}:\text{Hom}(X\times Y, Z) \to \text{Hom}(X, \text{Hom}(Y,Z)) , while uncurrying is the inverse map. If the set Y^X of continuous functions from X to Y is given the compact-open topology, and if the space Y is locally compact Hausdorff, then \text{curry} : Z^{X\times Y}\to (Z^Y)^X is a homeomorphism. This is also the case when X , Y and Y^X are compactly generated, although there are more cases. One useful corollary is that a function is continuous if and only if its curried form is continuous. Another important result is that the application map, usually called "evaluation" in this context, is continuous (note that eval is a strictly different concept in computer science.) That is, \begin{align} &&\text{eval}:Y^X \times X \to Y \\ && (f,x) \mapsto f(x) \end{align} is continuous when Y^X is compact-open and Y locally compact Hausdorff. These two results are central for establishing the continuity of homotopy, i.e. when X is the unit interval I , so that Z^{I\times Y} \cong (Z^Y)^I can be thought of as either a homotopy of two functions from Y to Z , or, equivalently, a single (continuous) path in Z^Y . [\Sigma X,Z] \approxeq [X, \Omega Z] where [A,B] is the set of homotopy classes of maps A \rightarrow B , and \Sigma A is the suspension of A, and \Omega A is the loop space of A. In essence, the suspension \Sigma X can be seen as the cartesian product of X with the unit interval, modulo an equivalence relation to turn the interval into a loop. The curried form then maps the space X to the space of functions from loops into Z , that is, from X into \Omega Z . Then \text{curry} is the adjoint functor that maps suspensions to loop spaces, and uncurrying is the dual. The duality between the mapping cone and the mapping fiber (cofibration and fibration) can be understood as a form of currying, which in turn leads to the duality of the long exact and coexact Puppe sequences. In homological algebra, the relationship between currying and uncurrying is known as tensor-hom adjunction. Here, an interesting twist arises: the Hom functor and the tensor product functor might not lift to an exact sequence; this leads to the definition of the Ext functor and the Tor functor. \text{curry}(f) = \lambda x.(\lambda y.(f(x,y))) where \lambda is the abstractor of lambda calculus. Since curry takes, as input, functions with the type (X\times Y)\to Z , one concludes that the type of curry itself is \text{curry}:((X \times Y)\to Z) \to (X \to (Y \to Z)) The → operator is often considered right-associative, so the curried function type X \to (Y \to Z) is often written as X \to Y \to Z . Conversely, function application is considered to be left-associative, so that f(x, y) is equivalent to ((\text{curry}(f) \; x) \;y) = \text{curry}(f) \; x \;y. That is, the parenthesis are not required to disambiguate the order of the application. Curried functions may be used in any programming language that supports closures; however, uncurried functions are generally preferred for efficiency reasons, since the overhead of partial application and closure creation can then be avoided for most function calls. \mathrm{Hom}(A\otimes B, C) \cong \mathrm{Hom}(A, B\Rightarrow C) . Here, Hom denotes the (external) Hom-functor of all morphisms in the category, while B\Rightarrow C denotes the internal hom functor in the closed monoidal category. For the category of sets, the two are the same. When the product is the cartesian product, then the internal hom B\Rightarrow C becomes the exponential object C^B . Currying can break down in one of two ways. One is if a category is not closed, and thus lacks an internal hom functor (possibly because there is more than one choice for such a functor). Another way is if it is not monoidal, and thus lacks a product (that is, lacks a way of writing down pairs of objects). Categories that do have both products and internal homs are exactly the closed monoidal categories. The setting of cartesian closed categories is sufficient for the discussion of classical logic; the more general setting of closed monoidal categories is suitable for quantum computation. The difference between these two is that the product for cartesian categories (such as the category of sets, complete partial orders or Heyting algebras) is just the Cartesian product; it is interpreted as an ordered pair of items (or a list). Simply typed lambda calculus is the internal language of cartesian closed categories; and it is for this reason that pairs and lists are the primary types in the type theory of LISP, Scheme and many functional programming languages. By contrast, the product for monoidal categories (such as Hilbert space and the vector spaces of functional analysis) is the tensor product. The internal language of such categories is linear logic, a form of quantum logic; the corresponding type system is the linear type system. Such categories are suitable for describing entangled quantum states, and, more generally, allow a vast generalization of the Curry–Howard correspondence to quantum mechanics, to cobordisms in algebraic topology, and to string theory. The linear type system, and linear logic are useful for describing synchronization primitives, such as mutual exclusion locks, and the operation of vending machines. Intuitively, partial function application says "if you fix the first 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 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. Partial application can be seen as evaluating a curried function at a fixed point, e.g. given f \colon (X \times Y \times Z) \to N and a \in X then \text{curry}(\text{partial}(f)_a)(y)(z) = \text{curry}(f)(a)(y)(z) or simply \text{partial}(f)_a = \text{curry}_1(f)(a) where \text{curry}_1 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 f(x,y) , a function g(y,x) may be defined such that g(y,x) = f(x,y) . 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.

References

  1. ^ "Currying Schonfinkelling" . Portland Pattern Repository Wiki . Cunningham & Cunningham, Inc. 6 May 2012. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  2. ^ Barendregt, Henk; Barendsen, Erik (March 2000) [December 1998]. Introduction to Lambda Calculus (PDF) (Revised ed.). p. 8. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  3. ^ Curry, Haskell ; Feys, Robert (1958). Combinatory logic . Vol. I (2 ed.). Amsterdam, Netherlands: North-Holland Publishing Company. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  4. ^ Hutton, Graham; Jones, Mark P., eds. (November 2002). "Frequently Asked Questions for comp.lang.functional, 3. Technical topics, 3.2. Currying" . University of Nottingham Computer Science . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  5. ^ Heim, Irene; Kratzer, Angelika (January 2, 1998). Semantics in Generative Grammar (PDF) . Malden, Massachusetts: Blackwell Publishers, an imprint of Wiley. ISBN 0-631-19712-5 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  6. ^ Turner, David (1 Jun 1997). "Programming language, Currying, or Schonfinkeling?, #9 / 14" . Computer Programming Language Forum . Archived from the original on 3 March 2022 . Retrieved 3 March 2022 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  7. ^ "compactly generated topological space" . nLab . 28 May 2023. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  8. ^ Tillotson, J.; Booth, Peter I. (March 1980) [Received 2 October 1978, revised 29 June 1979, published 1 May 1980]. "Monoidal closed, Cartesian closed and convenient categories of topological spaces" (PDF) . Pacific Journal of Mathematics . 88 (1). Berkeley, California: Mathematical Sciences Publishers: 35– 53. doi : 10.2140/pjm.1980.88.35 . eISSN 1945-5844 . ISSN 0030-8730 . {{ cite journal }} : More than one of |location= and |publication-place= specified ( help ) Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  9. ^ "convenient category of topological spaces" . nLab . 11 August 2023. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  10. ^ Barendregt, Hendrik Pieter (1984). "Theorems 1.2.13, 1.2.14". The lambda calculus: its syntax and semantics . Studies in logic and the foundations of mathematics. Vol. 103 (Rev. ed.). North-Holland, an imprint of Elsevier. ISBN 978-0-444-87508-2 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  11. ^ Mac Lane, Saunders ; Moerdijk, Ieke (1992). "Chapter I. Categories of Functors; sections 7. Propositional Calculus, 8. Heyting Algebras, and 9. Quantifiers as Adjoints" . Sheaves in Geometry and Logic: A First Introduction to Topos Theory . New York: Springer-Verlag, part of Springer Science & Business Media. pp. 48– 57. ISBN 978-0-387-97710-2 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  12. ^ Abramsky, Samson; Coecke, Bob (5 March 2007). "A categorical semantics of quantum protocols". Logic in Computer Science (LICS 2004): Proceedings, 19th Annual IEEE Symposium, Turku, Finland, 2004] . IEEE Computer Society Press. pp. 415– 425. arXiv : quant-ph/0402130 . doi : 10.1109/LICS.2004.1319636 . ISBN 978-0-7695-2192-3 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  13. ^ Lee, G. Kay (15 May 2013). "Functional Programming in 5 Minutes" . Slides . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  14. ^ Schönfinkel, Moses (September 1924) [Presented at the Mathematischen Gesellschaft (Mathematical Society) in Göttingen on 7 December 1920. Received by Mathematische Annalen on 15 March 1924.]. "Über die Bausteine der mathematischen Logik" [On the building blocks of mathematical logic] (PDF) . Mathematische Annalen . 92 ( 3– 4). Berlin: Springer: 305– 316. doi : 10.1007/BF01448013 . S2CID 118507515 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  15. ^ Slonneger, Kenneth; Kurtz, Barry L. (1995). "Curried Functions, 5.1: Concepts and Examples, Chapter 5: The Lambda Calculus". Formal Syntax and Semantics of Programming Languages: A Laboratory Based Approach (PDF) . Addison-Wesley Publishing Company. p. 144. ISBN 0-201-65697-3 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  16. ^ a b Frege, Gottlob (1893). "§ 36" . Grundgesetze der arithmetik (in German). Book from the collections of University of Wisconsin - Madison, digitized by Google on 26 August 2008. Jena: Hermann Pohle. pp. 54– 55. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  17. ^ a b c Originally published as Reynolds, John C. (1 August 1972). "Definitional interpreters for higher-order programming languages" . In Shields, Rosemary (ed.). Proceedings of the ACM annual conference - ACM '72 . Vol. 2. ACM Press. pp. 717– 740. doi : 10.1145/800194.805852 . ISBN 9781450374927 . S2CID 163294 . 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 Reynolds, John C. (1998). "Definitional Interpreters for Higher-Order Programming Languages" . Higher-Order and Symbolic Computation . 11 (4). Boston: Kluwer Academic Publishers: 363– 397. doi : 10.1023/A:1010027404223 . 13 – via Syracuse University: College of Engineering and Computer Science - Former Departments, Centers, Institutes and Projects. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  18. ^ a b Strachey, Christopher (April 2000) [This paper forms the substance of a course of lectures given at the International Summer School in Computer Programming at Copenhagen in August, 1967.]. "Fundamental Concepts in Programming Languages" . Higher-Order and Symbolic Computation . 13 : 11– 49. CiteSeerX 10.1.1.332.3161 . doi : 10.1023/A:1010000313106 . ISSN 1573-0557 . S2CID 14124601 . There is a device originated by Schönfinkel, for reducing operators with several operands to the successive application of single operand operators. {{ cite journal }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  19. ^ a b c Curry, Haskell B. (1980). Barwise, Jon; Keisler, H. Jerome; Kunen, Kenneth (eds.). "Some Philosophical Aspects of Combinatory Logic". The Kleene Symposium: Proceedings of the Symposium Held June 18-24, 1978 at Madison, Wisconsin, U.S.A. (Studies in Logic and the Foundations of Mathematics) . Studies in Logic and the Foundations of Mathematics. 101 . North-Holland Publishing Company, imprint of Elsevier: 85– 101. doi : 10.1016/S0049-237X(08)71254-0 . ISBN 9780444853455 . ISSN 0049-237X . S2CID 117179133 . Some contemporary logicians call this way of looking at a function "currying", because I made extensive use of it; but Schönfinkel had the idea some 6 years before I did. {{ cite journal }} : CS1 maint: periodical has ISBN ( link ) Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  20. ^ a b c cdiggins (24 May 2007). "Currying != Generalized Partial Application?!" . Lambda the Ultimate: The Programming Languages Weblog . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  21. ^ a b May, Jon Peter (1999). A concise course in algebraic topology (PDF) . Chicago lectures in mathematics. Chicago, Ill.: University of Chicago Press. pp. 39– 55. ISBN 0-226-51183-9 . OCLC 41266205 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  22. ^ a b c Quine, W. V. (1967). "Introduction to Moses Schönfinkel's 1924 "On the building blocks of mathematical logic" ". In van Heijenoort, Jean (ed.). From Frege to Gödel: A Source Book in Mathematical Logic, 1879-1931 . Harvard University Press. pp. 355– 357. ISBN 9780674324497 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  23. ^ a b Baez, John C.; Stay, Mike (6 June 2009). "Physics, Topology, Logic and Computation: A Rosetta Stone". In Coecke, Bob (ed.). New Structures for Physics (PDF) . Lecture Notes in Physics. Vol. 813: New Structures for Physics. Berlin, Heidelberg: Springer. pp. 95– 172. arXiv : 0903.0340 . doi : 10.1007/978-3-642-12821-9_2 . ISBN 978-3-642-12821-9 . S2CID 115169297 . Archived from the original (PDF) on 5 December 2022. {{ cite book }} : More than one of |publication-date= and |date= specified ( help ) Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  24. ^ a b c Rotman, Joseph Jonah (1988). "Chapter 11". An introduction to algebraic topology . Graduate texts in mathematics; 119. New York: Springer-Verlag. ISBN 978-0-387-96678-6 . OCLC 17383909 . Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
  25. ^ a b c "Partial Function Application is not Currying" . The Uncarved Block . 7 August 2020. Archived from the original on 23 October 2016. Wikipedia revision 1378651937, retrieved 2026-11-18 · 1794956400.0
source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Currying". 1791199424. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1378651937

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·