Hacker News new | ask | show | jobs
by thaumasiotes 1358 days ago
> Actual currying would allow you to do partial application this way, making it less explicit

> 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.

1 comments

The original `f` was a binary function:

  f = lambda x, y: x + y
My updated curried `f` is a unary function, but it returns a unary function itself:

  f = lambda x: lambda y: x + y
That's what currying is. I just reused the name, if you prefer:

  curried_f = lambda x: lambda y: x + y
EDIT:

And note, it makes the partial application less explicit/verbose than the original, but the currying is very explicit because of Python's syntax.

  g = curried_f(3)
Is "just" a function call, while:

  g = lambda y: f(3, x)
does the same thing (functionally, at least) but the partial application is made explicit.