Proposal: Add strict iterate'

David Feuer david.feuer at gmail.com
Wed Jul 30 00:48:04 UTC 2014


I think most if not all applications of iterate would prefer to accumulate
strictly—iterating a constant function is not very useful and the spine of
the result of iterate is always the same. Unlike unfoldr, which has enough
strictness built in to allow its caller to decide whether to accumulate
strictly, iterate is entirely lazy. I therefore propose:

iterate' :: (a -> a) -> a -> [a]
iterate' f b = unfoldr go b
  where
    go x = x `seq` Just (x, f x)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140729/35453493/attachment.html>


More information about the Libraries mailing list