currying at language level (was: Re: add_command)
holger krekel
pyth at devel.trillke.net
Mon May 13 13:31:32 EDT 2002
Alex Martelli wrote:
> 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?)
does it need to? IOW what problems do you expect?
i think the usual TypeErrors when e.g. supplying multiple
values for an argument are straight forward to come up
with.
> (is currying important enough to
> deserve special syntax, and, if so, what is the right
> sugar for it?)
There are some good reasons IMO for making it a syntax thing
but first the concepts, agreed.
> 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.
yes. Only it is not so easy to get even a
builtin to provide 'enough' convenience. Consider one of
my currying implementations which does it like so:
f1=PrebindFunc(f, BINDLATER, 2, BINDLATER, karg1="hehe")
But how can you get around the special name 'BINDLATER'?
Take 'XXX'? Somehow it doesn't seem right to me to
try to makeup a name. Not unless there is a standardization
on ONE name which is hard to achieve.
> > 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.
I don't know haskell, sorry, but just currying the
leftmost arguments is quite restrictive and doesn't
fit to python's functio model IMO.
> 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.
If people knew how to do it and if it were easy to type
they'd like it, i guess. Wouldn't you?
It may be *a bit* like with 'yield'. Once you get it you
don't want to live without it. But you didn't know before.
Or maybe _you_ did :-)
holger
More information about the Python-list
mailing list