[Haskell-cafe] Bug in Data.Stream?

Peter Verswyvelen bugfact at gmail.com
Sat Apr 11 18:26:37 EDT 2009

Since I realized my code was always using infinite lists, I replaced it by
However, my code stopped working.

The problem is with these functions:

scan :: (a -> b -> a) -> a -> Stream b -> Stream ascan f z (Cons x xs)
=  z <:> scan f (f z x) xs-- | @scan'@ is a strict scan.scan' :: (a ->
b -> a) -> a -> Stream b -> Stream ascan' f z (Cons x xs) =  z <:>
(scan' f $! (f z x)) xs

They are too strict I think. My code works again when I add a lazy
pattern match:

scan f z ~(Cons x xs) =  z <:> scan f (f z x) xs

scan' f z ~(Cons x xs) =  z <:> (scan' f $! (f z x)) xs

This is justified since they then behave like scanl on lists. However
it seems this package is used a lot, so maybe some code depends on
this strictness.

What to do?

PS: Why does scanl' not exist in Data.List?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090412/a1dbc70d/attachment.htm

More information about the Haskell-Cafe mailing list