Ответ 1
Вот пример, показывающий большую часть основного материала, включая визуализацию типизированных URL-адресов.
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Data.Text
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet hiding (renderHtml)
data Url = Haskell | Yesod
renderUrl Haskell _ = pack "http://haskell.org"
renderUrl Yesod _ = pack "http://www.yesodweb.com"
title = pack "This is in scope of the template below"
template :: HtmlUrl Url
template = [hamlet|
<html>
<head>
#{title}
<body>
<p>
<a [email protected]{Haskell}>Haskell
<a [email protected]{Yesod}>Yesod
|]
main = do
let html = template renderUrl
putStrLn $ renderHtml html
Вывод:
<html><head>This is in scope of the template below</head>
<body><p><a href="http://haskell.org">Haskell</a>
<a href="http://www.yesodweb.com">Yesod</a>
</p>
</body>
</html>