This code is from the book "Learn You a Haskell for Great Good!":
maximum' :: (Ord a) => [a] -> a
maximum' [] = error "maximum of empty list"
maximum' [x] = x
maximum' (x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = maximum' xs
It works fine on non-empty lists, but supplying an empty list:
main = print $ maximum' []
gives this compiler error:
Ambiguous type variable ‘a0’ arising from a use of ‘maximum'’ prevents the constraint ‘(Ord a0)’ from being solved.
Why is that? Shouldn't the code actually catch it when an empty list is supplied? I don't understand the error message.