list - Why does adding the error case break my implementation of last? -


this code works fine:

last' :: [a] -> last' (x:[]) = x last' (x:xs) = last xs 

but if try add:

last' [] = error "empty list" 

anywhere. error:

"couldn't match type 'a' [char] -> a0'  'a' rigid type variable bound type signature last' :: [a] -> in expression: error  in equation last': last [] = error "empty list" 

why this? implementations of head, tail , init did not scream when put in case empy list.

i'm idiot. had typos. thanks!

adding error not breaking code. should correct implementation:

last' :: [a] -> last' (x:[]) = x last' (x:xs) = last' xs  -- xs not x last' [] = error "empty list" 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -