|
|
|
|
|
by Jtsummers
1358 days ago
|
|
Not quite, that is partial application. Actual currying would allow you to do partial application this way, making it less explicit: > g = f(3) # no second parameter provided
g = <unary function> # however it would be indicated in the python shell
To get it in Python you'd need to do this: f = lambda x: lambda y: x + y
g = f(3) # result is a function, or funcallable, or whatever Python calls the resultant type
This makes the currying explicit. In general, currying is taking an n-ary function and reducing it to a series of n unary functions. These three are equivalent, in Haskell(ish, rusty): f x y = x + y
g x = \y -> x + y
h = \x -> \y -> x + y
In Haskell, you don't have to use the explicit form of `h` (or the explicit form in the Python example) if you don't want to (and it would probably be weird if you used it extensively). |
|
> To get it in Python you'd need to do this:
> f = lambda x: lambda y: x + y
> This makes the currying explicit. In general, currying is taking an n-ary function and reducing it to a series of n unary functions.
Something's gone wrong; your example of explicit currying conflicts with your definition of currying. `f` is a unary function.