[Haskell-beginners] String type hello-o-matic...

Antoine Latter aslatter at gmail.com
Fri Mar 9 18:07:15 CET 2012


On Fri, Mar 9, 2012 at 9:01 AM, Emacs The Viking <sean at objitsu.com> wrote:
>
> I am almost to the point of exasperation on trying to know when and why and
> how to convert between String, ByteString, ByteString.Laz, Char8 etc. For
> heavens sake how many bloody string types can you need? LOL
>

Here is a really important point I'd like to make:

The 'sha1' function operates on _binary_data_.

If you have a 'String' or a 'Text' value, you have to make a _choice_
how you wish to represent your textual data as binary data.

That's why their are multiple types - because different situations can
call for different choices.

The Data.ByteString.Char8 module makes one choice - it truncates all
Unicode code-points above 255 to 255.

In many circumstances, this is not the right choice. But it's not
always the wrong choice either.

A great choice is UTF-8 - available either in the module
Data.Text.Encoding (for 'Text' values) or in the utf8-string package
for String values (using the functions 'fromString' and 'toString').

Antoine

http://hackage.haskell.org/packages/archive/text/0.11.1.13/doc/html/Data-Text-Encoding.html
http://hackage.haskell.org/packages/archive/utf8-string/0.3.7/doc/html/Data-ByteString-UTF8.html



More information about the Beginners mailing list