Currying

In mathematics and computer science, currying 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 that takes two arguments, one from and one from and produces objects in The curried form of this function treats the first argument as a parameter, so as to create a family of functions The family is arranged so that for each object in there is exactly one function

In this example, itself becomes a function, that takes as an argument, and returns a function that maps each to The proper notation for expressing this is verbose. The function belongs to the set of functions Meanwhile, belongs to the set of functions Thus, something that maps to will be of the type With this notation, is a function that takes objects from the first set, and returns objects in the second set, and so one writes 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.[1][2] The example above can be used to illustrate partial application; it is quite similar. Partial application is the function that takes the pair and together as arguments, and returns Using the same notation as above, partial application has the signature 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.[3]

The concept of currying was introduced by Gottlob Frege,[4][5] developed by Moses Schönfinkel,[6][5][7][8][9][10][11] and further developed by Haskell Curry.[8][10][12][13]

Uncurrying is the dual transformation to currying, and can be seen as a form of defunctionalization. It takes a function whose return value is another function , and yields a new function that takes as parameters the arguments for both and , and returns, as a result, the application of and subsequently, , to those arguments. The process can be iterated.

  1. ^ cdiggins (24 May 2007). "Currying != Generalized Partial Application?!". Lambda the Ultimate: The Programming Languages Weblog.
  2. ^ Cite error: The named reference uncarved was invoked but never defined (see the help page).
  3. ^ Cite error: The named reference rosetta was invoked but never defined (see the help page).
  4. ^ 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.
  5. ^ a b 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.
  6. ^ 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.]. Written at Moskau. "Ü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.
  7. ^ 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.
  8. ^ a b Originally published as Reynolds, John C. (1 August 1972). "Definitional interpreters for higher-order programming languages". In Rosemary Shields (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.
  9. ^ 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.
  10. ^ a b Cite error: The named reference haskell was invoked but never defined (see the help page).
  11. ^ "Currying Schonfinkelling". Portland Pattern Repository's Wiki. Cunningham & Cunningham, Inc. 6 May 2012.
  12. ^ Barendregt, Henk; Barendsen, Erik (March 2000) [December 1998]. Introduction to Lambda Calculus (PDF) (Revised ed.). p. 8.
  13. ^ Curry, Haskell; Feys, Robert (1958). Combinatory logic. Vol. I (2 ed.). Amsterdam, Netherlands: North-Holland Publishing Company.

© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search