Currying is a process of transforming an operation on two variables into an operation on one variable. The term is used in computer science and the lambda calculus, where it is often technically important to have operations that act on only one variable at a time. But category theory also recognises it as a natural isomorphism in a closed monoidal category.
Since most people are familiar with Set, we work there first. In , currying transforms a function defined on a cartesian product to a function that takes values in a function set. That is, starting with
we curry to produce
according to the formula
Similarly, in lambda calculus, currying is a device which reduces the study of functions in several arguments to functions in one argument. For example, if is a lambda term in which variables and occur freely (so that is effectively a “function” of and ), the lambda calculus syntax favors the currified expression , which denotes the intuitive expression , where one abstracts variables one at a time.
Later it was observed (by Lawvere) that this is just a special case of a more general “curryfication” for cartesian closed categories (such as Cat or a nice category of spaces), where one has a natural bijection of morphisms:
Indeed, cartesian closed categories are models for lambda calculus.
In fact, currying can be done in any (right) closed monoidal category. In that case, currying transforms a morphism whose source is a tensor product to a morphism whose target is an internal hom. That is, starting with
we curry to produce
Currying is invertible and natural in ; that is, is a natural isomorphism (in any closed monoidal category).
By convention, currying is always done on the last variable. This fits in very nicely with a convention that products associate on the left while internal homs associate on the right. More explicitly, if we use (as is common in computer science) ‘’ for the product (even if it is not cartesian) and ‘’ for the internal hom (so that we must use another symbol, say ‘’, for the external hom), then we need no parentheses to generalise currying
by currying several times in succession, we turn
This does not generalise to , which is one way to see that even the untyped lambda calculus actually has two objects, one of which is a terminal object and one of which can play every other role.
In a closed braided monoidal category (such as a closed symmetric monoidal category, and including the cartesian closed categories such as and the models of lambda calculus), we can also ‘curry through the first variable’ or ‘co-curry’ to produce a map
In a left closed monoidal category, currying does not exist, but cocurrying does. Perhaps the product should associate on the right in a left closed monoidal category?