Petri Lehtinen pe...@digip.org added the comment:
@markonervo: Have you tried the pointfree library:
http://pypi.python.org/pypi/pointfree/ ? I think it's exactly what you're
asking for.
The only case I've ever needed currying was managing callback soup in async
code. And even then,
Collin Winter coll...@gmail.com added the comment:
I assume I was added to this thread since I wrote the functional module, so
I'll give my take in that capacity. IMO Python doesn't need a more general
version of partial(); indeed, I question the need for partial() as it is today.
Querying
New submission from Marko Nervo ma...@python.it:
I think it would be very usefull to add a curry function to the functools
module. It should be like this.
def curry(func, *args, **kwargs):
if (len(args) + len(kwargs)) = func.__code__.co_argcount:
return func(*args, **kwargs)
Ezio Melotti ezio.melo...@gmail.com added the comment:
This sounds similar to
http://wiki.python.org/moin/PythonDecoratorLibrary#Pseudo-currying
Do you have a concrete use case for this?
--
nosy: +ezio.melotti
versions: +Python 3.3 -Python 2.7, Python 3.4
Antoine Pitrou pit...@free.fr added the comment:
You can use functools.partial for similar effect. Not sure what a dedicated
curry() primitive would improve.
--
nosy: +pitrou
___
Python tracker rep...@bugs.python.org
Alex Gaynor alex.gay...@gmail.com added the comment:
This already exists, as functools.partial:
http://docs.python.org/library/functools.html#functools.partial
--
nosy: +alex
resolution: - invalid
status: open - closed
___
Python tracker
Marko Nervo ma...@python.it added the comment:
In [1]: import functools
In [2]: def adder(x, y, z):
...: return (x + y + z)
...:
In [3]: adder = functools.partial(adder)
In [4]: adder(2)(3)(4)
---
TypeError
Éric Araujo mer...@netwok.org added the comment:
To go back to your original message:
I think it would be very usefull to add a curry function to the functools
module.
For what use cases?
Curried functions could be used as follow.
adder(2, 3, 4)
adder(2, 3)(4)
adder(2)(3)(4)
adder(z =
Ezio Melotti ezio.melo...@gmail.com added the comment:
FWIW there is a somewhat related thread that proposed a new syntax for curried
functions: http://mail.python.org/pipermail/python-ideas/2009-March/003220.html
--
stage: - committed/rejected
___
Marko Nervo ma...@python.it added the comment:
I totally disagree with the syntax for curried function, but I think a curry
function is perfect for the functools module and I also think it could be
useful at least as functools.partial. In addition, a lot of languages support
currying, such as
Antoine Pitrou pit...@free.fr added the comment:
However, here an example less confusional
adder = curry(lambda (x, y): (x + y))
adder3 = adder(3)
adder3(4)
7
adder3(5)
8
Currying let you defining new functions on other functions.
But so does functools.partial. So the question
Ezio Melotti ezio.melo...@gmail.com added the comment:
In that thread Guido said:
Haskell has this too, perhaps even more extreme: there's not really
such a thing in Haskell as a function of N arguments (N 1). f a b =
... defines a function f of one argument a which returns another
function (f
Marko Nervo ma...@python.it added the comment:
But so does functools.partial. So the question is, what use case does it
help that functools.partial doesn't?
Sure, it's common `defining new functions on other functions`... more times.
Here a stupid example with fold (our reduce).
@curry
def
Antoine Pitrou pit...@free.fr added the comment:
Sure, it's common `defining new functions on other functions`... more
times. Here a stupid example with fold (our reduce).
@curry
def fold(function, start, sequence):
if len(sequence) == 0:
return start
else:
Marko Nervo ma...@python.it added the comment:
You will have to try a bit
harder and showcase examples of *useful* code that are made
significantly easier through the use of curry().
Curry is a more advanced functools.partial. So, it could be used *at least* as
partial, but it is more
15 matches
Mail list logo