Discussion:
[Haskell-beginners] string -> bytestring
Christopher Howard
2013-01-01 10:53:44 UTC
Permalink
Hi. I'm trying to use pcre-light in a small text-manip app. However, the
module seems to want the incoming text data as a ByteString, whereas I
in my child-like naivety am taking the data from stdin as Strings. After
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'
--------

So I'm not sure what to do.
--
frigidcode.com
Iustin Pop
2013-01-01 12:03:44 UTC
Permalink
Post by Christopher Howard
Hi. I'm trying to use pcre-light in a small text-manip app. However, the
module seems to want the incoming text data as a ByteString, whereas I
in my child-like naivety am taking the data from stdin as Strings. After
searching around, I tried using the fromString function from
--------
Couldn't match expected type `ByteString'
with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
--------
So I'm not sure what to do.
Is it a mismatch between strict and lazy bytestrings?

iustin
Mateusz Kowalczyk
2013-01-01 13:31:50 UTC
Permalink
See the answer to
http://stackoverflow.com/questions/12576817/couldnt-match-expected-type-with-actual-type-error-when-using-codec-bmp

In the future, provide a small code snippet as well so that anyone
helping can easily point out where you're messing up.
Post by Iustin Pop
Post by Christopher Howard
Hi. I'm trying to use pcre-light in a small text-manip app. However, the
module seems to want the incoming text data as a ByteString, whereas I
in my child-like naivety am taking the data from stdin as Strings. After
searching around, I tried using the fromString function from
--------
Couldn't match expected type `ByteString'
with actual type `bytestring-0.9.2.1:Data.ByteString.Internal.ByteString'
--------
So I'm not sure what to do.
Is it a mismatch between strict and lazy bytestrings?
iustin
_______________________________________________
Beginners mailing list
http://www.haskell.org/mailman/listinfo/beginners
Christopher Howard
2013-01-01 20:41:45 UTC
Permalink
Post by Mateusz Kowalczyk
See the answer to
http://stackoverflow.com/questions/12576817/couldnt-match-expected-type-with-actual-type-error-when-using-codec-bmp
In the future, provide a small code snippet as well so that anyone
helping can easily point out where you're messing up.
_______________________________________________
Beginners mailing list
http://www.haskell.org/mailman/listinfo/beginners
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.
--
frigidcode.com
Daniel Fischer
2013-01-01 21:01:25 UTC
Permalink
Post by Christopher Howard
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.
Post by Christopher Howard
searching around, I tried using the fromString function from
--------
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.

Loading...