[Python-Dev] Re: PEP 309, function currying
Andrew Koenig
ark-mlist at att.net
Tue Feb 24 10:08:32 EST 2004
> I like curry(). The others don't bring the right concept to mind for me.
> I apologise if this offends the purists, but *all* of the recent attempts
> to "clarify" the difference between partial application and currying have
> simply confused me.
Let me try an example, partly to be sure I understand it.
Suppose have a function f with five arguments. Then I think you are
proposing a function, which I shall call X for the moment, with the property
that evaluating
g = X(f, a, b)
z = g(c, d, e)
has the same effect as
z = f(a, b, c, d, e)
At least, that's how the code in the PEP seems to behave.
If so, that's not currying. Currying would work like this:
g = curry(f) # Note -- no other arguments
g1 = g(a)
g2 = g1(b)
g3 = g2(c)
g4 = g3(d)
z = g4(e)
with z having the same value as f(a, b, c, d, e) afterward.
Note that curry takes only one argument, namely f. Instead of taking an
argument of f directly, it returns a function that will accept f's first
argument. It is that extra level of indirection that distinguishes currying
from partial application.
More information about the Python-Dev
mailing list