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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

Reply via email to