dynamically generated runtime methods & reflection
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Fri Jun 15 12:58:11 EDT 2007
Alex Martelli a écrit :
> Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com>
> wrote:
>
>> Josiah Carlson a écrit :
>> (snip)
>>> Well, the particular operation is typically called 'currying a
>>> function',
>> <pedantic>
>> it's not 'currying' but 'partial application'.
>>
>> Currying is somehow the reverse of partial : it's a way of building a
>> multiple-args function from single-args functions.
>> </pedantic>
>
> Wikipedia says
>
>"currying or Schönfinkelisation[1] "
cf below...
> "is the technique of
> transforming a function that takes multiple arguments into a function
> that takes a single argument"
The definition commonly agreed upon (in the FP world at least) is that
currying is the process that "build" ("emulate", whatever...)
multiple-args functions in a context that only supports single-arg
functions (ie: ML, Haskell), so that (using Python syntax):
f(x, y, z)
would really be in fact (and under the hood):
f(x)(y)(z)
where f(x) returns a function closing over(x) and taking y, itself
returning a function closing over x and y and taking z...
Talking about this:
"""
currying (...) reduces multiple-argument
functions to single-argument functions only (Schoenfinkel,
1924)
"""
http://srfi.schemers.org/srfi-26/mail-archive/msg00015.html
So while *very closely* related to partial application, it's not exactly
the same thing.
FWIW, you can also have a look here:
http://www.python.org/dev/peps/pep-0309/#motivation
> -- and FWIW I agree with Wikipedia in this
> case;
I don't - and I'm not the only one:
http://lambda-the-ultimate.org/node/2266
"""
I had mistakenly learned that curry was a form of generalized partial
application from the paper : Function Currying in Scheme by Jeffrey A.
Meunier
and the Wikipedia entry (I should have known better), however I was
mildly reprimanded for making this novice mistake in a recent paper
submission to ICFP
"""
> the reverse (going from single-arg to multiple-args)
Note that I didn't say "going from", but "building". The context is a
functional language where there's *no* such thing as "multiple args"
functions.
Re-reading, I can agree that my choice of words may have been a bit
poor, specially wrt/ the word "reverse". What I meant here was that
partial application is used in the context of multiple-args function to
'build' a function taking n-x arguments from a function taking n
arguments, while currying is used in the context of single-arg functions
to "emulate" multiple-args functions.
> would be
> "uncurrying", though I don't think I've ever used that term myself.
>
> functools.partial's name may be more precise (because it can, e.g., go
> from a function taking 3 arguments to one taking 2 -- not just from N
> down to 1)
>
> but your 'pedantic' remark seems pedantically wrong:-).
I certainly won't pretend knowing more about CS that you do, but given
the definition of currying in pep-0309 - which exactly matches the
definition I first learned when toying with Haskell -, I maintain my
pedantic remark until proven wrong - which BTW should not be overly
difficult if it happened to be the case !-)
As a last word, the original version of pep-0309 was named "curry", and
has been corrected since:
"""
It isn't function currying, but partial application. Hence the name is
now proposed to be partial().
"""
http://www.python.org/dev/peps/pep-0309/#feedback-from-comp-lang-python-and-python-dev
More information about the Python-list
mailing list