In the following, let’s define sum as
sum = function (a, b, c) a + b +cBecause base::sum’s definition involves ..., which would make the following explanation unnecessarily complex.
Partial function application takes a function f with n formal
parameters and m=1…n arguments, and fixes some of f formal
parameters by filling them in, thereby reducing f’s arity to n−m.
f = partial(sum, 1)
f()
f(2, 3)## 1
## 6
Currying takes a function f with n formal parameters and produces a
recursive nesting of n functions, each taking 1 formal parameter. Recursively
calling all these functions is then identical to calling the original function:
g = curry(sum)
g()
g(1)(2)(3)0
6
Conversely, uncurry reverses a currying:
foo = function (a)
function (b)
function (c)
a + b + c
foo(1)(2)(3)
bar = uncurry(foo)
bar(1, 2, 3)## 6
## 6