[Haskell-cafe] Is unfoldr too strict?

Vanessa McHale vanessa.mchale at iohk.io
Tue Dec 11 09:50:16 UTC 2018

I think the "official" version could be implemented with a lazy pattern
match and it'd be the same as yours, no?


On 12/11/18 12:55 AM, Isaac Elliott wrote:
> 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?) 
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181211/e11b10ab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20181211/e11b10ab/attachment.sig>

More information about the Haskell-Cafe mailing list