3 ms·
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 curryin
by boxed 3y ago
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.
- iso8859-1 3y agoIf 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.
- ivanjermakov 3y agoCould you share an example?
- bPspGiJT8Y 3y agoThis 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 = ...
- iso8859-1 3y agohttps://github.com/purescript/documentation/blob/master/language/Records.md https://github.com/purescript/documentation/blob/master/lang...
- boxed 3y agoI 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.
- mjarrett 3y agoOne 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).
- fs_tab 3y agoSomewhat 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)
- iso8859-1 3y agoTyping fixes this, and anonymous records make it even better. JavaScript lacks typing, and then they decided on a weird signature for the callback...
- simon04 3y agoUnfortunately 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.
- iso8859-1 3y agoIf 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 https://wiki.haskell.org/Newtype