I am trying to use a decoder from Data.Encoding
on some text that I'm not sure is encoded correctly. When I attempt to load the following code into haskell:
import Data.Encoding (DynEncoding,decodeLazyByteStringExplicit,encodingFromStringExplicit)
{- ...more imports ... -}
import qualified Data.ByteString.Lazy as B (ByteString,takeWhile)
{- ... more code ... -}
decodeMyString :: Encoding enc => B.ByteString -> enc -> Either String String
decodeMyString str decoder = case (decodeLazyByteStringExplicit decoder str) of
Left s -> Left $ show s
Right decoded -> Right decoder
I get the following error:
Couldn't match expected type `bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString'
with actual type `B.ByteString'
In the second argument of `decodeLazyByteStringExplicit', namely
`str'
In the expression: (decodeLazyByteStringExplicit decoder str)
In the expression:
case (decodeLazyByteStringExplicit decoder str) of {
Left s -> Left $ show s
Right decoded -> Right decoded }
Can anyone explain why? I have the latest versions of the libraries bytestring
(10.4) and encoding
(0.7). But it should not matter, because encoding's hackage page
does not specify a required version of bytestring.
At this point, I'm almost tempted to write my own set of decoders for non-unicode encodings of bytestrings
to convert them into utf-whatever bytestrings and use Data.Text.Encoding
but I shouldn't have to given the existence of Data.Encoding
.
That's a common problem when two different packages were assembled with different versions of the same library (ByteString in this case). A solution is here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.