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
Post a Comment