Skip to content

@joefiorini /error.log secret
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
test-hsp.hs:44:30:
Couldn't match type `ServerPartT IO'
with `HSPT XML (ServerPartT IO)'
In the first argument of `asChild', namely
`((asChild (getMethod)))'
In the expression: asChild ((asChild (getMethod)))
In the third argument of `genElement', namely
`[asChild
(fromStringLit
"We can use the ServerPartT monad too.\
\ Your request method was: "),
asChild ((asChild (getMethod)))]'
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
{-# OPTIONS_GHC -F -pgmFhsx2hs #-}
import HSP
import HSP.Monad
import HSP.ServerPartT
import Happstack.Server.HSP.HTML (defaultTemplate)
import Happstack.Server.XMLGenT
import Data.Text.Internal.Lazy
import Data.Functor
import Happstack.Server
( Response, ServerPart, ServerPartT(..), nullConf,
nullDir, ok, toResponse, rqMethod, simpleHTTP, askRq
)
main :: IO ()
main = simpleHTTP nullConf $ hello
template :: (EmbedAsChild (ServerPartT IO) body) => body -> ServerPartT IO XML
template body = defaultTemplate "" () body
hello :: ServerPart Response
hello = ok . toResponse =<< template
<div>
<h1>Hello HSP!</h1>
<p>We can insert Haskell expression such as this:
<% show $ sum [1 .. (10 :: Int)] %></p>
<p>We can use the ServerPartT monad too.
Your request method was: <% getMethod %></p>
<hr/>
<p>We don't have to escape & or >. Isn't that nice?</p>
<p>If we want <% "<" %> then we have to do something funny.</p>
<p>But we don't have to worry about
escaping <% "<p>a string like this</p>" %></p>
<p>We can also nest <% <span>like <% "this." %> </span> %></p>
</div>
where
getMethod :: XMLGenT (HSPT XML (ServerPartT IO)) String
getMethod = show . rqMethod <$> askRq
@stepcut
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -F -pgmFhsx2hs #-}

import HSP
import HSP.Monad
import HSP.ServerPartT
import Happstack.Server.HSP.HTML (defaultTemplate)
import Happstack.Server.XMLGenT

import Data.Text.Internal.Lazy

import Data.Functor

import Happstack.Server
    ( Response, ServerPart, ServerPartT(..), nullConf,
      nullDir, ok, toResponse, rqMethod, simpleHTTP, askRq
    )

main :: IO ()
main = simpleHTTP nullConf $ hello

template :: (EmbedAsChild (HSPT XML (ServerPartT IO)) body) => body -> ServerPartT IO XML
template body = unHSPT $ (defaultTemplate empty () body :: HSPT XML (ServerPartT IO) XML)

hello :: ServerPart Response
hello = ok . toResponse =<< template
    <div>
    <h1>Hello HSP!</h1>
    <p>We can insert Haskell expression such as this:
        <% show $ sum [1 .. (10 :: Int)] %></p>
    <p>We can use the ServerPartT monad too.
       Your request method was: <% getMethod %></p>
    <hr/>
    <p>We don't have to escape & or >. Isn't that nice?</p>
    <p>If we want <% "<" %> then we have to do something funny.</p>
    <p>But we don't have to worry about
       escaping <% "<p>a string like this</p>" %></p>
    <p>We can also nest <% <span>like <% "this." %> </span> %></p>
    </div>
  where
    getMethod :: XMLGenT (HSPT XML (ServerPartT IO)) String
    getMethod = show . rqMethod <$> askRq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.