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.
[ Parent
| on HN ]
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 = ...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.
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).
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)
Typing fixes this, and anonymous records make it even better.
JavaScript lacks typing, and then they decided on a weird signature for the callback...
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.
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