List function tails with scanr:
scanrTails = scanr (:) []
Unfortunately inits is harder as it needs to snoc the list, it has a slow definition with (++):
scanlInits = scanl snoc [] where
snoc xs x = xs++[x]
Or a more efficient one with Hughes lists (see diff list on Hackage):
type H a = [a] -> [a]
out :: H a -> [a]
out f = f []
snoc :: H a -> a -> H a
snoc f a = f . (a:)
scanlInits' :: [a] -> [[a]]
scanlInits' = map out . scanl snoc id
I had defined tails as a paramorphism which lead me to see it as a scan:
paraTails = para phi [[]] where
phi e (fwd,acc) = (e:fwd):acc
Para's definition is:
-- paramorphism (generalizes cata)
para :: (a -> ([a], b) -> b) -> b -> [a] -> b
para phi b = step
where step [] = b
step (e:es) = phi e (es, step es)