Currying

https://arbital.com/p/currying

by M Yass Jul 3 2016 updated Jul 18 2016

Transforms a function of many arguments into a function into a function of a single argument


Currying converts a Function of N [input inputs] into a function of a single input, which returns a function that takes a second input, which returns a function that takes a third input, and so on, until N functions have been evaluated and N inputs have been taken, at which point the original function is evaluated on the given inputs and the result is returned.

For example:

Consider a function of four parameters, $~$F:(X,Y,Z,N)→R$~$.

The curried version of the function, $~$curry(F)$~$ would have the type signature $~$X→(Y→(Z→(N→R)))$~$, and $~$curry(F)(4)(3)(2)(1)$~$ would equal $~$F(4,3,2,1)$~$.

Currying is named after the logician Haskell Curry. If you can't remember this derivation and need a mnemonic, you might like to imagine a function being cooked in a curry so thoroughly that it breaks up into small, bite-sized pieces, just as functional currying breaks a function up into smaller functions. (It might also help to note that there is a programming language also named after Haskell Curry (Haskell), that features currying prominently. All functions in Haskell are pre-curried by convention. This often makes partially applying functions effortless.)