I have the following code to create an empty html page with a series of divs with id 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
Functions dCand dIshould be empty with the class or identifier, respectively. In the interpreter, these functions work perfectly when concatenated, for example:
printf $ prettyHtmlFragment $ dC "1" +++ dC "2"
<div class="1">
</div>
<div class="2">
</div>
But not when I try to nest them using <<instead +++, I get an error:
<interactive>:1:28:
Couldn't match expected type `Html -> b'
against inferred type `Html'
This is what I consider the cause of the problem in the main part of the code, but I do not know how to fix it. Any ideas?
source
share