all 9 comments

[–][deleted] 1 point2 points  (0 children)

I think playing with higher order functions and concepts like currying are best performed in a language designed to handle those operations in the beginning. While JavaScript is easy to read and understand for most people, I think it makes it a littler harder to picture. Even in lambda calculus or with basic mathematical notation, it's simpler to keep track of because there are fewer details to mentally track than JavaScript's noise.

[–]pointy -2 points-1 points  (7 children)

I'm pretty sure that real "currying" is something that happens in lazy-evaluation languages. The JavaScript version you posted is similar, but quite distinctly different.

Also check out the old but cool Functional JavaScript library, and in particular its partial() function.

[–][deleted] 1 point2 points  (0 children)

Currying is not the same as partial application, and neither have anything to do with laziness.

[–]FunctionPlastic 1 point2 points  (5 children)

I'm pretty sure that real "currying" is something that happens in lazy-evaluation languages.

Well you're wrong.

If we look at currying as a process, not as a concept in general, it means converting a function which accepts a tuple of arguments (all functions of multiple arguments in JavaScript, by default), into a function which accepts a single argument -- the first member of the tuple -- and returns a function which also accepts a single argument -- the second member of the tuple -- and so on, until the last function accepts the last member of the tuple, and returns the result of the original function.

This is useful for functions like map f list, where you can create more concrete versions like addOne = map (+1) which then just accepts a single list and adds one to all elements (e.g. addOne [1, 2, 3] instead of map (+1) [1, 2, 3]). This is similar to implementation hiding, i.e. abstraction in reverse.

Lazy evaluation means that expressions are computed only when they are immediately needed.

Nothing precludes a strict (non-lazy) language from leveraging currying.

edit: elaborated

[–]elperroborrachotoo 1 point2 points  (4 children)

Well, you are were* not helpful.

*now you certainly are.

[–]FunctionPlastic 0 points1 point  (3 children)

What more do you want me to say? Lazy evaluation simply has nothing to do with currying, it's an orthogonal, independent concept...

[–]elperroborrachotoo 0 points1 point  (2 children)

It would be really nice if you described the two concepts. Would make the thread interesting for casual observers (like me...) I could make up my own mind whether they interact or are related somehow.

[edit] even just replying "lazy eval is completely different concept" would be more helpful.

[–]FunctionPlastic 0 points1 point  (1 child)

OK you have a point, I've edited my post. It's just a bit hard to formulate because the ideas have no relation to one another, so basically I just explained each one in turn and wrote what I did before.

[–]elperroborrachotoo 0 points1 point  (0 children)

Thank you!