Difference between revisions of "Strings"

From HaskellWiki
Jump to navigation Jump to search
(Initial page (stub))
 
 
Line 1: Line 1:
 
{{Stub}}
 
{{Stub}}
[[Category:Tutorials]]
 
   
 
There are several types of strings that can be used in Haskell programs.
 
There are several types of strings that can be used in Haskell programs.
   
== Strings ==
+
== String ==
   
<hask>String</hask> is the standard string type in Haskell; it is the same as <hask>[Char]</hask>. Strings are in Unicode.
+
<hask>String</hask> is the only string type mandated by the language standard, and as such is overwhelmingly the most common, especially for non-performance-sensitive applications. It is simply a type synonym for <hask>[Char]</hask>.
   
  +
Pros:
  +
* conceptually simple and easy to use
  +
* interfaces well with other list functions
  +
  +
Cons:
  +
* massive overhead, up to 4 words per character, which also has speed implications
  +
* not pedantically Unicode-correct in some cases (e.g. there are strings which change length when changing case, so <hask>map toLower</hask> is not accurate in that case)
   
 
== ByteString ==
 
== ByteString ==
Line 13: Line 19:
 
<hask>ByteString</hask> is a type defined in the package [http://hackage.haskell.org/package/bytestring bytestring], available from Hackage.
 
<hask>ByteString</hask> is a type defined in the package [http://hackage.haskell.org/package/bytestring bytestring], available from Hackage.
   
  +
Bytestrings are sequences of ''bytes'' not characters, and aren't really a text type at all. They are best used for binary data.
There are two version of <hask>ByteString</hask>s: lazy and strict.
 
 
 
=== Lazy ByteString ===
 
 
TODO
 
 
 
=== Strict ByteString ===
 
 
TODO
 
   
  +
They are low-overhead in space terms and very heavily optimised – they are a key part of writing high-performance code in Haskell.
   
 
=== Data.ByteString.Char8 ===
 
=== Data.ByteString.Char8 ===
   
 
TODO
 
TODO
 
   
 
== Text ==
 
== Text ==

Latest revision as of 20:38, 2 March 2014

This article is a stub. You can help by expanding it.

There are several types of strings that can be used in Haskell programs.

String

String is the only string type mandated by the language standard, and as such is overwhelmingly the most common, especially for non-performance-sensitive applications. It is simply a type synonym for [Char].

Pros:

  • conceptually simple and easy to use
  • interfaces well with other list functions

Cons:

  • massive overhead, up to 4 words per character, which also has speed implications
  • not pedantically Unicode-correct in some cases (e.g. there are strings which change length when changing case, so map toLower is not accurate in that case)

ByteString

ByteString is a type defined in the package bytestring, available from Hackage.

Bytestrings are sequences of bytes not characters, and aren't really a text type at all. They are best used for binary data.

They are low-overhead in space terms and very heavily optimised – they are a key part of writing high-performance code in Haskell.

Data.ByteString.Char8

TODO

Text

For a more efficient processing of text, there is Text, defined in the package text.

There are two version of Texts: lazy and strict.


Lazy Text

TODO


Strict Text

TODO


Links

  • string-conversions; this package provides a simple type class for converting values of different string types into values of other string types.