[Python-Dev] Re: PEP 309, function currying

Gareth McCaughan gmccaughan at synaptics-uk.com
Tue Feb 24 07:06:32 EST 2004


Paul Moore wrote:

> 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.

Partial application is specifying some of the arguments
of a function, so you get a new function that takes fewer
arguments.

Currying is making a function take one argument at a time,
doing partial application as it goes.

Highbrow but enlightening example: Suppose F is a function
that takes a programming language spec and a program in that
language, and executes the program. (You could call it a
"generic interpreter".) Then

  - Partial application turns F into a specialized interpreter,
    such as a Python interpreter. The partially applied function
    takes fewer parameters, because some have been fixed.

  - Currying turns F into an interpreter generator. You feed it
    a language spec and it spits out an interpreter. The curried
    function takes the same number of parameters, but you give it
    them in a different way.

"Curry plus call equals partial-apply."

> If curry() gets screams of outrage, someone suggested bind() to follow the
> Boost C++ library's usage. That's tolerable, although I find it too generic
> a word.

I think I like that better than the other proposals currently
on the table.

                                  *

By the way, "purists" are more likely to be offended by being
caricatured ("purists", "screams of outrage") than by the fact
that someone has difficulty understanding what they say. But it's
no big deal.

-- 
g





More information about the Python-Dev mailing list