'Patterns non-exhaustive in function that finds last element of list [closed]

Started learning haskell, now starting to go through the 99 haskell problems. Need to find the last element of a list.

-- (*) Find the last element of a list.

-- Example in Haskell:

-- λ> myLast [1,2,3,4]
-- 4
-- λ> myLast ['x','y','z']
-- 'z'

myLast :: (Show a) => [a] -> a
myLast [] = error "Can't call myLast on an empty list!"  
myLast [x] = x
mylast (x:xs) = myLast xs


main = print $ myLast [1,2,3,9]

When compiling and running the code, ie

ghc ex1.hs
./ex1

I get the complaint "Non-exhaustive patterns in function myLast".

Excuse the noobish question, but why are my patterns non exhaustive? As far as I can tell, I have a pattern for an empty list, a pattern for a list containing one element, and a pattern for a list containing more than one element.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source