[Haskell-cafe] Data.ByteString woes

David Carter david.m.carter at gmail.com
Wed Apr 15 07:16:01 EDT 2009


I am battling with Data.ByteString.Lazy.Char8, and currently losing.
Any help gratefully received. Here's my code:

import qualified Data.ByteString.Lazy.Char8 as B
import Text.Regex.Posix ((=~))
test = B.pack "abc" =~ B.pack "b" :: Bool

This works fine without the ".Lazy", and is also fine under GHC 6.8.1,
but with GHC 6.10.1, it fails with:

    No instances for (Text.Regex.Base.RegexLike.RegexLike
                        Text.Regex.Posix.Wrap.Regex B.ByteString,

I then thought I might work around the problem by converting lazy
ByteStrings to strict ones in order to do the regex match. I
discovered toChunks, which is advertised in the documentation as type
ByteString -> [ByteString], but it actually appears to be of type

toChunks :: ByteString -> [Data.ByteString.Internal.ByteString]

and I can't see any way of converting a
Data.ByteString.Internal.ByteString to a (strict) ByteString.

Does anyone know whether this is (a) bug(s) in GHC, Data.ByteString,
Text.Regex.Posix or (maybe most likely) my own limited understanding?
And any ideas for fixes or workarounds (other than the obvious one of
downgrading to GHC 6.8)?

Thanks in advance


More information about the Haskell-Cafe mailing list