module Stail where stail :: [a] -> Maybe [a] stail [] = Nothing stail (x : xs) = case stail xs of Nothing -> Just [] _ -> Just xs stail2 :: [a] -> Maybe [a] stail2 [] = Nothing stail2 (x : xs) = Just (case stail2 xs of Nothing -> [] _ -> xs) stail2Fold :: [a] -> Maybe (a,[a]) stail2Fold = foldr (\ x r -> Just (case r of Nothing -> (x,[]) Just (y,tl) -> (x , y : tl))) Nothing