[Haskell-cafe] Is unfoldr too strict?

Isaac Elliott isaace71295 at gmail.com
Tue Dec 11 06:55:07 UTC 2018


I was reading this article
https://wiki.haskell.org/Correctness_of_short_cut_fusion on the Haskell
wiki. It presents an example (2.1.2) where destroy/unfoldr fusion behaves
oddly. If I use a lazier definition of unfoldr, then this problem goes away:

unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
> unfoldr f b =
>   case f b of
>     Nothing -> []
>     Just z -> fst z : unfoldr f (snd z)


Does this mean unfoldr is 'too strict'? Or is there a good reason for not
writing it this way (performance, perhaps?)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181211/8ccd2fca/attachment.html>


More information about the Haskell-Cafe mailing list