Strict, lazy, and builder

Contents
  • Modules and types
  • Text vs bytes
  • Converting between Text and ByteString
  • Strict (“packed”) strings
  • Lazy strings
  • String builders

Here we look at two common Haskell libraries, text and bytestring, and addressing the frequently-asked question: “Why are there so many types of strings?”

We’ll examine the differences between various string types, talk about what situations in which each is appropriate, and see what functions the libraries give us to convert among them.

Modules and types

We will discuss these three types from the text package

and these three types from the bytestring package

All of these modules are intended to be used with qualified imports. Herein we use a conventional set of qualified names:

import qualified Data.Text               as T
import qualified Data.Text.Lazy          as LT
import qualified Data.Text.Lazy.Builder  as TB
import qualified Data.ByteString         as BS
import qualified Data.ByteString.Lazy    as LBS
import qualified Data.ByteString.Builder as BSB

Sign up for access to the full page, plus the complete archive and all the latest content.