Note that there are some explanatory texts on larger screens.

plurals
  1. POText or Bytestring
    primarykey
    data
    text
    <p>Good day. </p> <p>The one thing I now hate about Haskell is quantity of packages for working with string.</p> <p>First I used native Haskell <code>[Char]</code> strings, but when I tried to start using hackage libraries then completely lost in endless conversions. Every package seem to use different strings implementation, some adopts their own handmade thing.</p> <p>Next I rewrote my code with <code>Data.Text</code> strings and <code>OverloadedStrings</code> extension, I chose <code>Text</code> because it has a wider set of functions, but it seems many projects prefer <code>ByteString</code>.<br /> Someone could give short reasoning why to use one or other?</p> <p>PS: btw how to convert from <code>Text</code> to <code>ByteString</code>?</p> <blockquote> <p>Couldn't match expected type <em>Data.ByteString.Lazy.Internal.ByteString</em> against inferred type <em>Text</em> Expected type: IO Data.ByteString.Lazy.Internal.ByteString Inferred type: IO Text</p> </blockquote> <p>I tried <code>encodeUtf8</code> from <code>Data.Text.Encoding</code>, but no luck:</p> <blockquote> <p>Couldn't match expected type <em>Data.ByteString.Lazy.Internal.ByteString</em> against inferred type <em>Data.ByteString.Internal.ByteString</em></p> </blockquote> <p><strong>UPD:</strong></p> <p>Thanks for responses, that *Chunks goodness looks like way to go, but I somewhat shocked with result, my original function looked like this:</p> <pre><code>htmlToItems :: Text -&gt; [Item] htmlToItems = getItems . parseTags . convertFuzzy Discard "CP1251" "UTF8" </code></pre> <p>And now became:</p> <pre><code>htmlToItems :: Text -&gt; [Item] htmlToItems = getItems . parseTags . fromLazyBS . convertFuzzy Discard "CP1251" "UTF8" . toLazyBS where toLazyBS t = fromChunks [encodeUtf8 t] fromLazyBS t = decodeUtf8 $ intercalate "" $ toChunks t </code></pre> <p>And yes, this function is not working because its wrong, if we supply <code>Text</code> to it, then we're confident this text is properly encoded and ready to use and converting it is stupid thing to do, but such a verbose conversion still has to take place somewhere outside <code>htmltoItems</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload