[Haskell-beginners] When to use ByteString rather than [Char] ... ?

Felipe Lessa felipe.lessa at gmail.com
Sun Apr 11 11:08:18 EDT 2010


On Sun, Apr 11, 2010 at 12:07:34PM +0100, James Fisher wrote:
> use the Data.ByteString library rather than standard [Char]

These are different.

IN THE PAST:
  - We used String for everything, both strings and binary data.

IN RECENT PAST:
  - We used String for treating... strings of characters.
  - We used ByteString for binary data.

  - To read an UTF-8 string we used a package like utf8-string:
     1) Read file as ByteString.
     2) Convert UTF-8 bytes into String, a list of Chars.

TODAY:
  - ByteString is used for binary data.
  - String is used for text when performance isn't critical.
  - Data.Text (from package 'text') is used for text when time
    and/or space efficiency is needed.

Data.Text uses the same 'tricks' as ByteString, but while the
latter encodes bytes, the former encodes Char's.

HTH,

--
Felipe.


More information about the Beginners mailing list