Good afternoon.
The only thing I hate about Haskell is the number of packages to work with the string.
At first I used my own Haskell [Char] strings, but when I tried to start using the hackage libraries, I was completely lost in endless conversions. It seems that each package uses an implementation of different strings, some of them accept their own handmade thing.
Then I rewrote my code using the Data.Text lines and the OverloadedStrings extension, I selected Text because it has a wider range of functions, but it seems that many projects prefer ByteString .
Someone can give a short explanation why to use this or that?
PS: btw, how to convert from Text to ByteString ?
Cannot match expected type Data.ByteString.Lazy.Internal.ByteString versus expected type Text Expected type: IO Data.ByteString.Lazy.Internal.ByteString Derived type: IO Text
I tried encodeUtf8 from Data.Text.Encoding but no luck:
Cannot match the expected type of Data.ByteString.Lazy.Internal.ByteString versus the output type Data.ByteString.Internal.ByteString
UPD:
Thanks for the answers that * Chunks goodness looks like a way to go, but I'm somewhat shocked by the result, my original function looked like this:
htmlToItems :: Text -> [Item] htmlToItems = getItems . parseTags . convertFuzzy Discard "CP1251" "UTF8"
And now it has become:
htmlToItems :: Text -> [Item] htmlToItems = getItems . parseTags . fromLazyBS . convertFuzzy Discard "CP1251" "UTF8" . toLazyBS where toLazyBS t = fromChunks [encodeUtf8 t] fromLazyBS t = decodeUtf8 $ intercalate "" $ toChunks t
And yes, this function does not work, because it is incorrect if we supply it with Text , then we are sure that this text is correctly encoded and ready for use, and the conversion is a stupid thing, but such a detailed conversion should still occur somewhere- then outside htmltoItems .
string text haskell
Dfr Sep 09 '11 at 6:13 2011-09-09 06:13
source share