News for hackers. Stuff that matters.
Re:Currying by boxed on Sunday April 07, 2024 @06:11AM (#39959737)
Currying makes positional only parameters look cooler and fancier. It's a trap. Labeled arguments is the way to go for 99% of all parameters. Accidental currying is horrible.
Re:Currying by iso8859-1 on Sunday April 07, 2024 @08:30PM (#39965158)
If you look at how people actually write PureScript, which is much like Haskell, but with anonymous records, you can see that they're not actually used 99% of the time.
Re:Currying by ivanjermakov on Sunday April 07, 2024 @10:12PM (#39965634)
Could you share an example?
Re:Currying by bPspGiJT8Y on Monday April 08, 2024 @10:26AM (#39970071)
This function would use an anonymous record:

    splitString :: { pattern :: String, string :: String } -> Array String
    splitString { pattern, string } = ...
This function would use positional arguments:

    splitString :: Pattern -> String -> Array String
    splitString pattern string = ...
Re:Currying by iso8859-1 on Monday April 08, 2024 @10:35AM (#39970171)
Re:Currying by boxed on Monday April 08, 2024 @04:43AM (#39967570)
I write quite a bit of Elm and I use currying a lot. I really wish it was explicit. Or at least that my IDE could highlight them.
Re:Currying by mjarrett on Monday April 08, 2024 @09:50AM (#39969710)
One of my favorite features in OCaml is labeled arguments. You get a similar flavor of partial application, but without the strict argument order requirement (most of the time -- higher order functions are strict about labeled-function arguments).
Re:Currying by fs_tab on Monday April 08, 2024 @09:59AM (#39969777)
Somewhat related - be wary of implicit parameter passing in function pipelines. For example, Try ['10', '10', '10'].map(Number.parseInt) in your browser console. What's actually being called is:

Number.parseInt('10', 0) Number.parseInt('10', 1) Number.parseInt('10', 2)

Re:Currying by iso8859-1 on Monday April 08, 2024 @10:40AM (#39970221)
Typing fixes this, and anonymous records make it even better.

JavaScript lacks typing, and then they decided on a weird signature for the callback...

Re:Currying by simon04 on Monday April 08, 2024 @12:42PM (#39971456)
Unfortunately typing doesn't fix this. The 2nd callback function argument of Array.map is (index:number), and the 2nd argument of Number.parseInt is (radix:number).

It's a very nasty issue to debug.

Re:Currying by iso8859-1 on Monday April 08, 2024 @03:27PM (#39972872)
If there were typing, there would be no reason to not use newtypes[0] for radix and index. These values should only be explicitly unwrapped to plain numbers.

It would look like this

    newtype Radix = Radix { radixToWord :: Word }
    newtype Index = Index { indexToWord :: Word }
[0]: https://wiki.haskell.org/Newtype