Currying (after Haskell Curry) is the bijection between functions of two variables and functions returning functions:
“If I have a function of two variables , I can put off entering the second variable: if you give me just , I’ll return a function that’s waiting for the input.” Categorically it is the Adjunction defining the Exponential Object; in general categories it is the defining property of a Cartesian Closed Category, and is one: (functors can be curried, DaoFP §9.7).
Sources: 7 Sketches Example 3.72, Exercise 3.73; DaoFP Chapter 6 (“Currying”, “Relation to lambda calculus”), §10.1 (“The Currying Adjunction”), §10.5; Kittenlab (implicit: Julia closures); CTfS §2.7.2 (Proposition 2.7.2.3, Exercises 2.7.2.2–2.7.2.6)
- Force–extension curves (CTfS §2.7.2). An experiment measuring the force transmitted by a material pulled to an extension is a function . Currying repackages it as — each material has its force–extension curve — or as : at a fixed extension, compare all materials. Same information, three packagings. The inverse of currying applied to the identity of is evaluation , (CTfS Exercise 2.7.2.5); and follows from (CTfS Exercise 2.7.2.6).
- 7S Exercise 3.73: acts on morphisms by ; acts by ; currying gives .
- Lambda calculus (DaoFP §6): a term corresponds to an arrow ; -abstraction is currying, application is the counit ; -reduction and -conversion are the two triangle identities. Haskell functions are curried by default:
f :: a -> b -> cisa -> (b -> c). - Unit and counit:
unit = curry id :: e -> (a -> (e, a))andcounit = uncurry id :: (a -> b, a) -> b(function application). - The preorder shadow: the hom-element of a Monoidal Closed Preorder, iff — ” and suffice to get iff suffices to get a single-use -to- converter”.
Docs: Theories (Catlab)
curry(f) = x -> y -> f(x, y)
uncurry(g) = (x, y) -> g(x)(y)
add3 = curry(+)(3); add3(4) # 7import Mathlib
#check @Function.curry -- (α × β → γ) → α → β → γ
#check @Function.uncurry
#check Equiv.curry -- (α × β → γ) ≃ (α → β → γ)
#check @CategoryTheory.MonoidalClosed.curry -- in any (cartesian) monoidal closed categorycurry :: ((a, b) -> c) -> (a -> b -> c)
curry f a b = f (a, b)
uncurry :: (a -> b -> c) -> ((a, b) -> c)
uncurry g (a, b) = g a b
-- Exercise 3.73: currying (+) and applying to 3
add3 :: Int -> Int
add3 = curry (uncurry (+)) 3