Non exhaustive pattern in function in GHCi
问题 I want to make a function that displays the last element of a list. This is my code: ghci> let myLast :: [a] -> a ghci> let myLast [] = error ghci> let myLast [x] = x ghci> let myLast (x:xs) = myLast xs And I get the following error: ***Exception: Non-exhaustive patterns in function myLast I understood that you get this error when you\'re missing a case, but I think I have included all the possibilities. Any ideas? 回答1: If you use a let in each line, each definition will make a new function