Re:Why Haskell?
by itishappy on Thursday September 12, 2024 @05:20PM
(#41525698)
I get it! (Thanks, playing around with actual code helped a ton.) For example, in Typescript you're saying you can add a default value simply:
But in Haskell this requires changing the call sites:
But I actually feel this is an antipattern in Haskell (and maybe TypeScript too), and a separate wrapper function avoids refactoring while making things even more user friendly.
Here's some wrappers for general functions (not that they're needed, they're essentially just raw prelude functions):
Added bonus, this approach avoids slowing down existing code with the null checks we just added.
[ Parent
| on HN ]
Got `maybeOut` wrong, can't edit, but it should be:
maybeOut :: (a -> b) -> (a -> Maybe b)
maybeOut = (.) Just
Also the parenthesis around the last two output types are added for emphasis, but can be safely removed.