News for hackers. Stuff that matters.
Re:Currying in JavaScript by layer8 on Sunday September 19, 2021 @12:13PM (#28585476)
One aspect I don’t like about currying (at least with the usual syntax) is that it privileges the first parameter of each function. As soon as you want to curry on the second parameter, you lose the "natural" currying syntax and have to fall back to e.g. `half x = \x -> div x 2` or something like `half = flip div 2`. That aspect, to me, makes currying nonuniform and awkward, as in many cases the first parameter doesn’t have a particular conceptual distinction to single it out for currying. It’s a bit similar to how I don’t like Smalltalk’s asymmetric syntax for commutative operations (e.g. `x add: y`).
Re:Currying in JavaScript by mLuby on Sunday September 19, 2021 @02:44PM (#28586798)
Agreed. I've come to view partial application as the original coder saying "I guarantee you'll never need to inspect or modify this parameter from now on." Obviously, that's rarely true in practice.

What about partial application of named parameters?

Re:Currying in JavaScript by savanaly on Sunday September 19, 2021 @11:51PM (#28590231)
>What about partial application of named parameters?

Builder pattern. In a language that accommodates it well, such as Elm, it would look like this:

    IconLib.downloadIcon
      |> IconLib.withSize 12
      |> IconLib.withColor "red"
      |> IconLib.withCssClass "dl-icon"
Allowing currying of any parameter like:

    standardDownloadIcon = IconLib.downloadIcon
      |> IconLib.withSize 12

    largeDownloadIcon = IconLib.downloadIcon
      |> IconLib.withSize 16
Re:Currying in JavaScript by josephcsible on Sunday September 19, 2021 @12:24PM (#28585563)
You can curry the second parameter without it being too ugly like this:

  half = (`div` 2)
Also, I think the idea with curried languages is that you're supposed to write your functions with the parameter that people are most likely to want to curry first.
Re:Currying in JavaScript by layer8 on Sunday September 19, 2021 @01:09PM (#28585975)
Of course that’s the mitigation strategy, but my point is that the usual currying syntax inherently special-cases the first parameter, and in x% of the situations that’s not what you want. From a language-design point of view it just feels awkward.
Re:Currying in JavaScript by josephcsible on Sunday September 19, 2021 @05:26PM (#28588082)
I guess that's fair. What about Scala's _ syntax, though? Does it solve the problem?