In prelude, head has the following signature : head :: [a] -> a which makes it unsafe on empty list, which is not good !! (head :: [a] -> Maybe a is the good way :-) )
this applies for a couple of other functions on list : last, tail, init minimum, maximum, cycle, last, init, foldl1, cycle... there are actually a lot of these calling errorEmptyList
Quoting Stephen Diehl from his website :
"Safe provides Maybe versions of many of the various partial functions (head, tail) that are shipped by default. Wrapping it up in a Maybe is widely considered the right approach and if Haskell were designed today, they would not be present."
I would love to see these unsafe functions tagged somehow with some convention at least because I don't think any of us like when an exception blows up in production :-)
What prevents the community from fixing these issues in the prelude ?
head :: Unsafe => [a] -> a, such that one can "turn off" unsafe functions, but unfortunately it is "too late", by introducing that, it would break a lot of existing code. Furthermore a lot of functions have been designed without such signature, hence it would be of "limited" use. - Willem Van Onsemhead, but if you know for sure you are dealing with a non-empty list, then this is not unsafe, so you can make a very conservative approach where you mark everything that uses unsafe functions as unsafe. But this will act like a "virus" contaminating a lot of functions that are safe. - Willem Van Onsem