[Haskell-beginners] string -> bytestring
Daniel Fischer
daniel.is.fischer at googlemail.com
Tue Jan 1 22:01:25 CET 2013
On Dienstag, 1. Januar 2013, 11:41:45, Christopher Howard wrote:
>
> With some more research, I figured it out: The problem was, it seems,
> that 8 bit ByteStrings are not the same as UTF8 ByteStrings. So I used
> the pack function from Data.ByteString.Char8, and this compiles fine.
It's not that. The UTF8 ByteStrings are the ordinary ByteStrings, the utf8-
string package just provides a few utility functions encoding, decoding etc.
> searching around, I tried using the fromString function from
> Data.ByteString.UTF8 to convert from String to ByteString; but all I get is:
>
> code:
> --------
> Couldn't match expected type `ByteString'
> with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
> --------
That means that your utf8-string package was built against version 0.9.2.1 of
the bytestring package, but you have a newer version installed, and that
package is what is used in the current module.
So fromString creates a bytestring-0.9.2.1:Data.ByteString.Internal.ByteString
- which is the exact package version and location of the definition of the
type - while the consumer expected ByteString from bytestring-0.10.0.0 (or
so).
Whenever an error message specifies a package version in a type error (be it
"Couldn't match expected..." or a "No instance..." class error), the problem
is that more than one package version is involved. You need to
- specify the exact version of the package to use with a `-package` flag,
- use Cabal to specify the exact versions of the packages, or
- rebuild the offending package(s) against newer versions of the dependencies
to make them compatible with the automatically chosen versions.
Unless your Strings only contain ASCII symbols, using
Data.ByteString.Char8.pack is probably wrong, since that just truncates Chars
to the least significant 8 bits.
Reinstall your utf8-string so that it is built using the current bytestring
version you have,
$ ghc-pkg unregister utf8-string
$ cabal install utf8-string
If you have other packages depending on utf8-string, ghc-pkg should warn about
breaking them and not unregister utf8-string at first. If those aren't too
many, reinstalling them too would be the best option.
More information about the Beginners
mailing list