Created
July 29, 2010 12:24
-
-
Save tibbe/497980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import qualified Data.ByteString.Lazy as S | |
import qualified Data.Text as T | |
import qualified Data.Text.Lazy.Encoding as E | |
import Data.Text.Template | |
-- | Create 'Context' from association list. | |
context :: [(T.Text, T.Text)] -> Context | |
context assocs x = maybe err id . lookup x $ assocs | |
where err = error $ "Could not find key: " ++ T.unpack x | |
main :: IO () | |
main = S.putStr $ E.encodeUtf8 $ substitute helloTemplate helloContext | |
where | |
helloTemplate = "Hello, $name!\n" | |
helloContext = context [("name", "Joe")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment