
10 Nov
2014
10 Nov
'14
4:50 a.m.
Hello, I tried to solve the first problem of the 99 haskell problems on 3 seperate ways. The problem is that I have to find the last item of a list. The solutions I found with a little help of this mailinglist are : last2::[a]-> Maybe a; last2 [] = Nothing; last2 ([x]) = Just x; last2 (_:xs) = last2 xs last3::[a]-> Maybe a; last3 x | null x = Nothing | null xs = Just (head x) | otherwise = last3 (tail x) where xs = tail x last4::[a]-> Maybe a; last4 x = case x of [] -> Nothing ; [x] -> Just x ; (_:xs) -> last4 xs main = print $ (last2 [] ) What do you experts think of the different ways ? Roelof