Why is scanr strict in its third argument?

David Feuer david.feuer at gmail.com
Thu Nov 9 16:06:59 UTC 2017


I think this discussion would be more appropriate to the libraries list.

On Nov 9, 2017 11:05 AM, "Geraint Jones" <Geraint.Jones at wolfson.ox.ac.uk>
wrote:

> There are two things you might think of when you think of scanr;
> or rather, there are two things I think of: a specification
>
>         scanr f e = map (foldr f e) . tails
>
> and an implementation
>
>         scanr f e = foldr g [e] where g x yss@(ys:_) = f x ys : yss
>
> Of course these two differ, because the one I called an implemntation
> is strict wheras the specification isn't.
>
> I wouldn't mind, but scanl goes to the trouble of not being strict,
> as does Data.List.tails, which means inter alia that scanr (:) [] is
> not an implementation of Data.List.tails as you might have expected.
> (Well, as I did.)
>
>
> In the context of
>
> > arb = error "not used in demo"
> > bot = error "bottom"
>
> you get
>
> *Main> (null . map (foldr arb arb) . Data.List.tails) bot
> False
> *Main> (null . scanr arb arb) bot
> *** Exception: bottom
> *Main> (null . scanl arb arb) bot
> False
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20171109/9e2111ba/attachment.html>


More information about the Glasgow-haskell-users mailing list