Home > Net >  Effect of import order on ByteString type signature
Effect of import order on ByteString type signature

Time:03-01

I'm puzzled by GHCI's behavior around Data.ByteString and Data.ByteString.Char8. If I load a file with the following imports

import qualified Data.Text as T
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.Text.Encoding as E

I get

*Main> :t E.encodeUtf8
E.encodeUtf8 :: T.Text -> BC.ByteString

If I reverse the second and third import lines to

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as B
import qualified Data.Text.Encoding as E

I get

*Main> :t E.encodeUtf8
E.encodeUtf8 :: T.Text -> B.ByteString

What that suggests to me is that Data.ByteString and Data.ByteString.Char8 are sharing the same ByteString type, but I don't know how to make sense of that.

CodePudding user response:

I think sjakobi's comment answers the question:

These modules do export the very same ByteString type. The difference between these modules is in the functions they expose.

  • Related