Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

    myData = [ [ ("name", "Databender"), ("title", "Dr.") ],
               [ ("name", "Paragon"), ("title", "Master") ],
               [ ("name", "Marisa"), ("title", "Madam") ] ]
  3. Define the template for the data as follows:

    myTemplate = template "Hello...