Working with text and bytestring
In this recipe, we will look at alternative representations of string. The string is a list of Char and is not an efficient implementation. The text
and bytestring
packages are the most popular packages for alternative and efficient string implementations. While text
implements unicode characters, bytestring
is good for binary data. In this recipe, we will work with these data types and convert them into each other, and also explore a GHC extension for strings.
How to do it...
- Create a new project
working-with-text-and-bytestring
with thesimple
Stack template:
stack new working-with-text-and-bytestring simple
- Add dependency on the
text
andbytestring
libraries in thebuild-depends
subsection of theexecutable
section:
executable working-with-text-and-bytestring hs-source-dirs: src main-is: Main.hs default-language: Haskell2010 build-depends: base >= 4.7 && < 5 ...