import Data.List (tails) suffixes :: [a] -> [[a]] suffixes xs@(_:xs') = xs : suffixes xs' -- as pattern. -- binds xs to the value on the right of the @ suffixes _ = [] -- same thing without as-pattern -- This will do a copy of the data, the as-pattern doesn't suffixesNoAs (x:xs) = (x:xs) : suffixesNoAs xs suffixesNoAs _ = [] -- even better suffixes2 :: [a] -> [[a]] suffixes2 xs = init (tails xs) compose :: (b -> c) -> (a -> b) -> a -> c compose f g x = f (g x) suffixes3 xs = compose init tails xs suffixes4 = compose init tails -- no need to invent the compose function suffixes5 = init . tails