ByteString, foldr and lazyness

Mathieu Boespflug mboes at
Thu Nov 27 09:08:09 EST 2008

Hi all,

Here's a ghci session, using bytestring- and ghc-6.10:

Prelude> :m Data.ByteString.Lazy.Char8
Prelude Data.ByteString.Lazy.Char8> :m -Prelude
Data.ByteString.Lazy.Char8> foldr (:) [] (concat (Prelude.repeat "a"))
Loading package bytestring- ... linking ... done.
"*** Exception: stack overflow

By contrast, using Prelude's foldr and concat:

Prelude> foldr (:) [] (concat (repeat "a")) :: String
<prints out an infinite list>

Each bytestring chunk only contains one letter, so I would expect the
foldr of bytestring to behave just like that of the Prelude.

Is this a bug? A feature? From looking at the bytestring source code I
don't see why the code behaves this way.

Many thanks,


More information about the Libraries mailing list