[Haskell-cafe] Differences between QuasiQuotes and TemplateHaskell

Dominik Bollmann dominikbollmann at gmail.com
Mon Apr 11 13:59:44 UTC 2016


Hi,

Originally, I thought that QuasiQuotes build on top of TemplateHaskell,
since they just provide a way of parsing a string into a Template
Haskell AST. That is, a quasi-quoter is defined by four parsers of types

String -> Q Exp
String -> Q Pat
String -> Q Type
String -> Q Dec

that parse EDSLs into corresponding Haskell (abstract) syntax.

However, while playing around with the Shakespeare package's quasiquoter
hamlet, I noticed that (e.g.) a snippet

html = [hamlet|
  <html>
    <body>
      <h1>Hello World
 |] ()

has type Html and not (as I would expect) Q Exp. Hence, it seems as if
quasiquotes are spliced in implicitly?

This confuses me since in Template Haskell in general a quote (e.g.,)
[e| \x -> x |] has type Q Exp, which then needs to be explicitly spliced
in order to produce the id function \x -> x.

So why do quasiquotes not have types Q Exp, but rather concrete types?

If anyone could clarify my confusion, this would be great!

Dominik.



More information about the Haskell-Cafe mailing list