For functions with three or more arguments, how does currying
work?
I searched over SO and Google. Concrete examples given in e.g. What is 'Currying'? ; https://en.wikipedia.org/wiki/Currying are about binary functions f (x, y)
.
In that case, g = curry f
takes one parameter and produces a unary function (f x)
.
My question is:
How do we extend this consistently to a n-parameter function, e.g. f3 (x,y,z)
? (f3: X->Y->Z->U)
If the curry
operation is treated as a higher order function, it can't directly apply to f3
, because curry
expects a function of type (X,Y) -> Z
, and the argument of f3
is a triple, not a pair. The same issue arises with a function fn
that takes an n-tuple.
One solution might be to equate (x,y,z)
and (x,(y,z))
, then curry
seems to apply. Then curry f3 = (f3 x)
is of type (Y,Z) -> U
. But is this how curry is supposed to be?