Hi
I have the following code to generate a blank html page with a series of divs with id's and classes in Haskell using the Text.XHtml.Strict library:
module Main where
import Text.XHtml.Strict
import Text.Printf
page :: Html
page = pHeader +++ pTop +++ pBody +++ pFooter
pHeader :: Html
pHeader = header << thetitle << "Page title"
pTop :: Html
pTop = (dC "header") << (dI "title")
pFooter :: Html
pFooter = (dC "footer") << (dI "foottext")
pBody :: Html
pBody = body << (dC "main") << (dI "window") << (dI "content")
dC :: String -> Html
dC x = (thediv noHtml)! [theclass x]
dI :: String -> Html
dI x = (thediv noHtml) ! [identifier x]
main :: IO ()
main = do
printf $ prettyHtml $ page
The functions dC
and dI
should make an empty with a class or id respectively. In the interpreter these functions work fine when concatenating, as in:
printf $ prettyHtmlFragment $ dC "1" +++ dC "2"
<div class="1">
</div>
<div class="2">
</div>
But not when I try to nest them using <<
instead of +++
, I get an error:
<interactive>:1:28:
Couldn't match expected type `Html -> b'
against inferred type `Html'
This is what I think the cause of the problem in the main part of the code is, but I don't know how to fix it. Any ideas?