I apologize for the quantity of newbie questions and the length of this.
I want to get into Haskell, web development is what I do, so it seemed
like the best avenue to start out. Yesod overwhelmed me with
quasi-quotes and TH, and I really just want to build everything from the
ground up, but that's also leading to lots of frustrations.
I like Hamlet as a good compromise between writing HTML by hand but
omitting unnecessary aspects like closing tags. I can't get Hamlet
working in a route, though. I have:
home :: RouteT Sitemap (ServerPartT IO) Response
home = do
ok $ toResponse [hamlet|
$doctype 5
<html>
|]
This throws:
UI.hs:34:10:
No instance for (ToMessage (t0 -> Markup))
arising from a use of `toResponse'
In the second argument of `($)', namely
`toResponse
(\ _render_a8mn
-> id
((Text.Blaze.Internal.preEscapedText . pack)
"<!DOCTYPE html>\n\
\<html></html>"))'
In a stmt of a 'do' block:
ok
$ toResponse
(\ _render_a8mn
-> id
((Text.Blaze.Internal.preEscapedText . pack)
"<!DOCTYPE html>\n\
\<html></html>"))
In the expression:
do { ok
$ toResponse
(\ _render_a8mn
-> id
((Text.Blaze.Internal.preEscapedText . pack)
"<!DOCTYPE html>\n\
\<html></html>")) }
So I looked into Hamlet a bit more, and noticed that it uses blaze-html
for output. Markup appears to be an internal blaze-html class. Looking
at Happstack.Server.Response, it seems like it has Response instances
for at least Text.Blaze.Html, but I don't see how to get from Markup to
Html.
I found this blog post from a bit over 2 years ago:
http://tazj.in/en/1335123720
but I don't know if it's still accurate. In particular, I don't
understand why urlF is necessary:
appRoot = do
urlF <- renderFunction
ok $ toResponse $ siteLayout ([hamlet|
<p>Small demo application for Happstack, web-routes, Hamlet and Lucius.
<p>Add two numbers by going to /plus/int1/int2, e.g.
<a href=@{Plus 13 37}> here.
<p>Also other boring stuff, for example #
<a href=@{Echo Reverse "Penguins!"}>this.
|]) urlF
I found the happstack-hamlet library, but a comment in the source seems
to imply that it probably isn't necessary anymore. I don't know if that
is due to changes in Hamlet, or because it's so simple.
I guess if I had to boil my confusion down to one question, it's that
Hamlet seems to output Blaze. How do I go from the Markup type that it
outputs, to the Response type Happstack expects?
And, more generally, does this ever get easier? :) I don't think I'm
*this* bad of a coder, and I've written Scala for a number of years so
am used to thinking somewhat functionally. It just seems like everything
needs 8 million types to get something done. I understand the concept of
currying, but every function I encounter seems to specify a bunch of
parameters, type restrictions, etc. I've been doing lots of JavaScript
lately, and at least there I can type out function calls by hand and
from memory. I don't know that I'll ever fully remember:
home :: RouteT Sitemap (ServerPartT IO) Response
and if I don't specify that my routes don't compile, so seems like I'll
be doing lots of cutting and pasting. I really do want to like Haskell
since I like type safety and native compilation,, but this is the most
I've struggled with a language in a *long* time. :)