Currying

Currying is the transformation of a function that takes several arguments into a chain of functions that each take a single argument. Instead of supplying all arguments at once, you apply the function to the first argument, which yields a new function expecting the next, and so on until every argument has been provided. The Haskell documentation describes this directly: “applying add to one argument yields a new function which is then applied to the second argument.”

Because each step returns a function, a curried function can be given fewer arguments than it ultimately needs. The result is a specialized function waiting for the rest. The Haskell tutorial calls this “the partial application of a curried function,” noting that it “is one way that a function can be returned as a value.” Partial application is what makes currying useful in everyday code, letting a general function be fixed into a more specific one.

The technique is named after the logician Haskell Curry. The Haskell tutorial explains that “the name curry derives from the person who popularized the idea,” and the programming language Haskell itself is named after him. The underlying idea comes from the lambda calculus and earlier work in combinatory logic.

In Haskell and the ML family of languages, currying is the default: a function written to take several arguments is really a function that takes one argument and returns a function expecting the rest. This makes partial application natural and fits well with higher-order functions, which routinely receive these intermediate functions as values.