Personalizing messages using a text template

Sometimes we have a large list of usernames and relating data and we wish to individually send each person a message. This recipe will create a text template that will be filled out from the data.

Getting ready

Install the template library using cabal:

$ cabal install template

How to do it…

Perform the following steps in a new file called Main.hs:

  1. Import the libraries as follows:
    {-# LANGUAGE OverloadedStrings #-}
    
    
    
    import qualified Data.ByteString.Lazy as S
    import qualified Data.Text as T
    import qualified Data.Text.IO as TIO
    import qualified Data.Text.Lazy.Encoding as E
    import qualified Data.ByteString as BS
    import Data.Text.Lazy (toStrict)
    import Data.Text.Template
  2. Define the data we are dealing with as follows: ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.