4 ms·
> things like how head is antithetical to everything we like about Haskell What does this mean?
by rwmj 5y ago
> things like how head is antithetical to everything we like about Haskell
What does this mean?
- jim-jim-jim 5y ago`head` throws a runtime error when used on an empty list, where it should really return a value wrapped in `Maybe` instead. This is some accident of history afaik.
- Zababa 5y ago'head' is a function that returns the first element of a list. On empty lists, it raises an exception. I'm not sure what's the origin of this, I know that standard ML also does that. The thing is that ~20 years ago exceptions in functional programming languages were seen as something normal, whereas these days people tend to prefer sum types. So what they would want is for head on a list of number to return a Maybe number, which can be Just number, or Nothing. This would allow the compiler to check for errors, and allow for easier composition since Maybe is monadic (if you don't know what monads are, think of them as an ubiquitous interface, like Iterator in another language).