currying at language level (was: Re: add_command)

Alex Martelli aleax at aleax.it
Mon May 13 05:55:18 EDT 2002


holger krekel wrote:
        ...
>> def curry(func, *args, **kwds):
>>     def curried(f=func, a=args, k=kwds):
>>         return apply(f, a, k)
>>     return curried
> 
> Alex, what do you think about integrating the
> currying-concept into python's syntax like so:

I'd love to have built-in currying, but the syntax
sugar you propose is clearly too limited (e.g., how
does it apply to keyword-arguments?) and doubtful
in several ways (is currying important enough to
deserve special syntax, and, if so, what is the right
sugar for it?).  A more sensible, gradualistic
approach might be to look for consensus on the exact
functionality that can be encapsulated in a built-in,
or even as a curry function that might be part of a
new FP module -- _that_ one we might stand a chance to
get into the standard library, perhaps.  If and when
currying becomes so popular as to deserve its own
special syntax sugar, then it may be a better time to
debate the details of that sugar.

> IMHO currying is a well-understood concept

It sure is _in a specific way_, the one analyzed and
widely used by Dr Haskell Curry: applying a function
f (which you could consider an "N-argument function"
in traditional terms) to an argument a to yield a new
anonymous function which you could consider an "N-1
argument function" in traditional terms.

But this doesn't mean we know exactly what should be
done in presence of named/optional arguments and other
cases of variadic functions.  "Currying the 1st and
3rd args of a 3-argument functions" is also a somewhat
unexplored realm AFAIK.


Alex




More information about the Python-list mailing list