Proposal: Add a strictly accumulating scanl' to Data.List

David Feuer david.feuer at
Thu Jul 24 20:55:59 UTC 2014

Joachim Breitner wrote, in, a strictly
accumulating version of scanl, to be named scanl'. I was initially
concerned about its safety for fusion, but am now convinced of its
correctness and believe it should be added to Data.List.

scanl' :: (b -> a -> b) -> b -> [a] -> [b]
scanl' f a bs = build $ \c n ->
  a `seq` a `c`
  foldr (\b g x -> (let b' = f x b in b' `seq` (b' `c` g b')))
         (\b -> b `seq` n)

More information about the Libraries mailing list