Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Best practices for working with strings performantly in Haskell are basically: Use Data.ByteString/Data.ByteString.Lazy.</p> <p><a href="http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/" rel="noreferrer">http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/</a></p> <hr> <p>As far as the efficiency of the default string implementation goes in Haskell, it's not. Each <code>Char</code> represents a Unicode codepoint which means it needs at least 21bits per <code>Char</code>. </p> <p>Since a <code>String</code> is just <code>[Char]</code>, that is a linked list of <code>Char</code>, it means <code>String</code>s have poor locality of reference, and again means that <code>String</code>s are fairly large in memory, at a minimum it's <code>N * (21bits + Mbits)</code> where N is the length of the string and M is the size of a pointer (32, 64, what have you) and unlike many other places where Haskell uses lists where other languages might use different structures (I'm thinking specifically of control flow here), <code>String</code>s are much less likely to be able to be optimized to loops, etc. by the compiler.</p> <p>And while a <code>Char</code> corresponds to a codepoint, the Haskell 98 report doesn't specify anything about the encoding used when doing file IO, not even a default much less a way to change it. In practice GHC provides an extensions to do e.g. binary IO, but you're going off the reservation at that point anyway.</p> <p>Even with operations like prepending to front of the string it's unlikely that a <code>String</code> will beat a <code>ByteString</code> in practice.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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