News for hackers. Stuff that matters.
Re:Currying in JavaScript by brundolf on Sunday September 19, 2021 @12:22PM (#28585543)
> applies k parameters to the function returning an (n-k) parameters function, without actually running the function

What would be the use of this? Just delaying the execution of the function's side-effects?

I'll tip my hand: I'm working on a JS-like (and JS-targeted) language that I want to support partial-application/currying by default. Under the hood everything is represented in a curried way, but syntactically you can both define and invoke/partially-invoke functions with the more familiar syntax (commas). But this is fully superficial right now; it all happens at the parser level. Is there a downside to doing things this way?

Re:Currying in JavaScript by djur on Sunday September 19, 2021 @02:51PM (#28586862)
The downside is that curried functions make default, optional, and keyword parameters difficult to implement.

For defaults/optionals, given "fn f(x, y, z=10)", if "f(1, 2)" evaluates to "f(1)(2)", does that return a function or the result of "f(1)(2)(10)"? What if you have "fn f(x, y = 10, z)"? All of this is a lot easier if you can evaluate the full argument list at the time of function invocation.

As for keyword arguments, they just don't play well with any kind of enforced ordering.

Re:Currying in JavaScript by brundolf on Sunday September 19, 2021 @03:18PM (#28587066)
Got it.

I wonder if that ambiguity could be resolved using contextual type info? I.e. if one of the two interpretations fits the expected type, use that. Otherwise, type-error.

Maybe that would be confusing, not sure.

Re:Currying in JavaScript by flyingchipmann on Sunday September 19, 2021 @12:59PM (#28585877)
If you come from typical oop background like java. Imagine there is a function has 5 parameters, and you need to to provide the first 3 first. Then later on you are using this partially applied function somewhere else. You can even reuse it later with different 2 params. Compare to class, it's just like how you initialize an object with certain values, then do something else with this object.
Re:Currying in JavaScript by RexM on Sunday September 19, 2021 @04:22PM (#28587583)
Bagel?

I read your post yesterday. Good luck with your language!

Re:Currying in JavaScript by brundolf on Sunday September 19, 2021 @04:56PM (#28587848)
Yes, thanks! :)

To be honest this comments section has me seriously reconsidering the "everything is partially-applicable by default" feature, haha.