4 ms·
Seems like a bug, shouldn't that return a Maybe? (the equivalent in Swift returns an Optional)
by cballard 11y ago
Seems like a bug, shouldn't that return a Maybe? (the equivalent in Swift returns an Optional)
- dack 11y agoThere are libraries that reimplement these types of functions using Maybes for the reason you would guess. I think it's mostly a historical artifact at this point.
- chadaustin 11y agoThere is a Haskell function called headMay [1] that returns a Maybe, but the Prelude head function throws when given an empty list. Either way, pure code can throw exceptions in Haskell. Consider division by zero for example. [1] https://hackage.haskell.org/package/safe-0.3.9/docs/Safe.html https://hackage.haskell.org/package/safe-0.3.9/docs/Safe.htm...
- dllthomas 11y agoYeah, many (myself included) share the view that it's a wart in the Haskell standard lib. There are good alternatives to using that function, though (same for most of the other unfortunately partial functions).