Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell text package selection

Back in the day, everybody used to do text processing with String. But then some folks pointed out that this is actually very, very inefficient, and the ByteString package was born.

ByteString is great for handling binary data. But soon people pointed out that ByteString.Char8 is actually a massive kludge, and what you really want is real Unicode handling for external data. And with that, approximately thirty similar but incompatible Haskell packages for dealing with packed Unicode strings were born. And none of them could really get any traction, because... well, thirty is way too many!

My question: Has this problem been fixed yet? In other words, has the community settled on one package for doing this job? And if so, which one is it?

like image 951
MathematicalOrchid Avatar asked Jan 02 '14 19:01

MathematicalOrchid


1 Answers

I believe that the current gold standard is Data.Text, which you can install with

$ cabal install text

and which you should import qualified as

import qualified Data.Text as T

You create Text values in your code either by explicitly casting from String, as in

>> let str = T.pack "Hello, world"

or by using the OverloadedStrings language extension

>> :set -XOverloadedStrings
>> let str = "Hello, world" :: Text
like image 146
Chris Taylor Avatar answered Oct 14 '22 17:10

Chris Taylor