In computer science, currying, invented by Moses Schönfinkel and Gottlob Frege, and independently by Haskell Curry, is the technique of transforming a function that takes multiple arguments (or more accurately an n-tuple as argument) in such a way as it can be called as a chain of functions each with a single argument.
Nomenclature
The name "currying", coined by Christopher Strachey in 1967, is a reference to logician Haskell Curry. An alternative name, Schönfinkelisation, has been proposed.Definition
Given a function f of type , then currying it makes a function . That is, takes an argument of type and returns a function of type . Uncurrying is the reverse transformation.
Intuitively, currying says "if you fix some arguments, you get a function of the remaining arguments". For example, if function div stands for the curried form of the division operation x / y, then div with the parameter x fixed at 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 currying is that very often the functions obtained by supplying some but not all of the arguments to a curried function are useful; for example, many languages have a function or operator similar to plus_one. Currying makes it easy to define these functions.
Some programming languages have built-in syntactic support for currying, where certain multi-argument functions are expanded to their curried form; notable examples are ML and Haskell. Any language that supports closures can be used to write curried functions.
Mathematical view
In theoretical computer science, currying provides a way to study functions with multiple arguments in very simple theoretical models such as the lambda calculus in which functions only take a single argument.
When viewed in a set-theoretic light, currying becomes the theorem that the set of functions from to , and the set of functions from to the set of functions from to , are isomorphic.
In category theory, currying can be found in the universal property of an exponential object, which gives rise to the following adjunction in cartesian closed categories: There is a natural isomorphism between the morphisms from a binary product and the morphisms to an exponential object . In other words, currying is the statement that product and Hom are adjoint functors; this is the key property of being a Cartesian closed category.
See also
References
External links
- Currying in Python (despite the name, the article actually describes partial function application, which is different from currying)
- Implicit currying in Scheme
- Currying in Ruby
- Currying in Smalltalk
- Currying in Algol68G
- Currying != Generalized Partial Application! - post at Lambda-the-Ultimate.org
- Currying in Scala
- Currying in Perl
- Currying in Delphi 2009
This article is licensed under the GNU Free Documentation License.
Last updated on Wednesday October 01, 2008 at 20:32:37 PDT (GMT -0700)
View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation
Copyright © 2008, Dictionary.com, LLC. All rights reserved.
| Dictionary | Thesaurus | Reference |









