2

So, I'm parsing some JSON into a custom data type with aeson, and I can't seem to understand why Haskell needs to have two representations of certain types in a library. In my case, this is all related to text.

For example:

Couldn't match expected type `Data.ByteString.Internal.ByteString'
with actual type `B.ByteString'.

Uhm, what? How are those two not the same? Why is there Data.ByteString.ByteString and Data.ByteString.Internal.ByteString? I don't understand why those two are two distinct types and why I'd need to convert between them.

Is there a guide somewhere that covers the use of ByteStrings? I understand they are way more efficient than Strings if you're only dealing with ASCII.

Honza Pokorny
  • 3,205
  • 5
  • 37
  • 43

2 Answers2

6

Data.ByteString.ByteString is merely a reexport of Data.ByteString.Internal.ByteString, so the types are identical. However a strict and lazy bytestrings are different types, so I suspect the problem you're experiencing to be caused by B.ByteString actually being Data.ByteString.Lazy.ByteString.

If that doesn't help, please provide more context.

Bytestring is indeed the most efficient type for storing ASCII. Here's a tutorial on bytestring. String is very inefficient for most use cases, Text is the preferred alternative for unicode.

Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
2

Data.ByteString.Internal.ByteString is the same type as Data.ByteString.ByteString. I'm willing to bet larger sums of money than I have available to me that B is actually an import of Data.ByteString.Lazy.

So the error is actually that you're mixing Data.ByteString.ByteString with Data.ByteString.Lazy.ByteString. The fact that the .Internal sneaks in there is an artifact of there not being tools to tell GHC to report a module other than the one that defined the type as the canonical location of that type in error messages.

Carl
  • 26,500
  • 4
  • 65
  • 86