Last active
August 29, 2015 14:04
-
-
Save joefiorini/df363a9a48b5697616ca 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
test-hsp.hs:27:8: | |
Couldn't match type `XMLType (ServerPartT IO)' with `XML' | |
Expected type: XMLGenT (ServerPartT IO) XML | |
Actual type: XMLGenT (ServerPartT IO) (XMLType (ServerPartT IO)) | |
In the return type of a call of `genElement' | |
In the first argument of `unXMLGenT', namely | |
`(genElement | |
(Nothing, fromStringLit "html") | |
[] | |
[asChild | |
((genElement | |
(Nothing, fromStringLit "head") | |
[] | |
[asChild | |
((genElement (Nothing, fromStringLit "title") [] [...]))])), | |
asChild | |
((genElement | |
(Nothing, fromStringLit "body") | |
[] | |
[asChild ((asChild (body)))]))])' | |
In the expression: | |
unXMLGenT | |
(genElement | |
(Nothing, fromStringLit "html") | |
[] | |
[asChild | |
((genElement | |
(Nothing, fromStringLit "head") | |
[] | |
[asChild | |
((genElement (Nothing, fromStringLit "title") [] [...]))])), | |
asChild | |
((genElement | |
(Nothing, fromStringLit "body") [] [asChild ((asChild (body)))]))]) | |
test-hsp.hs:27:20: | |
Couldn't match type `StringType (ServerPartT IO)' | |
with `Data.Text.Internal.Lazy.Text' | |
Expected type: Maybe (StringType (ServerPartT IO)) | |
Actual type: Maybe Data.Text.Internal.Lazy.Text | |
In the expression: Nothing | |
In the first argument of `genElement', namely | |
`(Nothing, fromStringLit "html")' | |
In the first argument of `unXMLGenT', namely | |
`(genElement | |
(Nothing, fromStringLit "html") | |
[] | |
[asChild | |
((genElement | |
(Nothing, fromStringLit "head") | |
[] | |
[asChild | |
((genElement (Nothing, fromStringLit "title") [] [...]))])), | |
asChild | |
((genElement | |
(Nothing, fromStringLit "body") | |
[] | |
[asChild ((asChild (body)))]))])' | |
test-hsp.hs:32:25: | |
Couldn't match type `Data.Text.Internal.Lazy.Text' with `XML' | |
In the expression: asChild (fromStringLit "Hello, HSP!") | |
In the third argument of `genElement', namely | |
`[asChild (fromStringLit "Hello, HSP!")]' | |
In the first argument of `asChild', namely | |
`((genElement | |
(Nothing, fromStringLit "title") | |
[] | |
[asChild (fromStringLit "Hello, HSP!")]))' |
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 FlexibleContexts #-} | |
{-# OPTIONS_GHC -F -pgmFhsx2hs #-} | |
import HSP | |
import HSP.Monad | |
import Happstack.Server.HSP.HTML | |
import Happstack.Server.XMLGenT | |
import Data.Functor | |
import Happstack.Server | |
( Happstack, HasRqData, Method(GET, POST), Request(rqMethod) | |
, Response | |
, ServerPartT(..), ServerPart, WebMonad, FilterMonad, ServerMonad | |
, askRq, decodeBody, dir, defaultBodyPolicy, lookText | |
, mapServerPartT, nullConf, nullDir, ok, simpleHTTP | |
, seeOther, method | |
, toResponse | |
) | |
main :: IO () | |
main = simpleHTTP nullConf $ hello | |
template :: (XMLGenerator m, EmbedAsChild m body) => body -> ServerPartT IO XML | |
template body = unXMLGenT | |
<html> | |
<head> | |
<title>Hello, HSP!</title> | |
</head> | |
<body> | |
<% body %> | |
</body> | |
</html> | |
hello :: ServerPartT IO XML | |
hello = template $ unXMLGenT | |
<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