Greg Heartsfield home

Currying Versus Partial Application

I’ve noticed what seems to be a growing inclination to confuse currying functions, with partial function application. The recently updated HaskellWiki pages (currying, partial application) are helpful in understanding the difference.

I think the reason for this confusion is that functions in Haskell are curried by default, making it rare for someone learning Haskell to need to explicitly curry a function. Explicit partial application is pervasive though, so the error is almost always using “curry” when you mean “partial application.”

Quoting HaskellWiki: “Currying is the process of transforming a function that takes multiple arguments into a function that takes just a single argument and returns another function if any arguments are still needed.”

Since Haskell functions are already curried, we simulate standard non-curried functions by using tuple arguments. A non-curried addition function would look like:

add :: (Int, Int) -> Int
add i = (fst i) + (snd i)

We can’t immediately partially apply a single argument of “1” to this, in order to get an “increment” function. Using the curry function from Standard Prelude, we can transform this (poorly written) function, and immediately take advantage of partial application by giving it an argument (1):

increment :: Int -> Int
increment = curry add 1

The HaskellWiki Currying page has a couple quick puzzles at the end, which I’ve solved in a ghci transcript below:

Validate XHTML Validate CSS