[Haskell-cafe] Compatibility between Data.ByteString.Base and Data.ByteString.Lazy

Neil Bartlett neil at integility.com
Wed Nov 29 08:12:49 EST 2006


Firstly my apologies if this is an outrageously newbie question.

I am trying to write a binary protocol parser using Data.ByteString. I
have created a module "ByteParser" containing my parsing utilities, which
imports ByteString as:

  import qualified Data.ByteString as B

In my Main module, where all the IO happens, I want to use lazy
ByteStrings so I ask for the following imports:

  import ByteParser
  import qualified Data.ByteString.Lazy as L

The problem is that when I try to call a function in ByteParser with an
L.ByteString, the compiler complains that:

  Couldn't match expected type `Data.ByteString.Base.ByteString'
  against inferred type `L.ByteString'

Does this mean that the lazy version of ByteString is a completely
separate, incompatible type from the base version? Obviously I can work
around this problem by making ByteParser import Data.ByteString.Lazy
instead of Data.ByteString, but then ByteParser would not be able to work
with strict ByteStrings. Ideally I would like ByteParser to be agnostic
about the use of lazy versus strict ByteStrings. Is this a sensible and/or
possible thing to do?

Many thanks,

More information about the Haskell-Cafe mailing list