I have a problem with a function that should only return the tail of a list. These functions are myTail and should give useful results, even if the input is an empty list.
I want to understand all three ways: pattern matching, protected equation, and conditional expressions
it works:
> myTail_pat :: [a] -> [a] > myTail_pat (x:xs) = xs > myTail_pat [] = []
But this:
> myTail_guard (x:xs) | null xs = [] > | otherwise = xs
gives me an error: Program error: template match failure: myTail_guard [] How can I declare a function without templates?
Thanks.
list haskell tail
Tarion
source share