[Haskell-cafe] Differences between QuasiQuotes and TemplateHaskell
eir at cis.upenn.edu
Mon Apr 11 14:15:25 UTC 2016
Counterintuitively, quasiquotes are like TH *splices* not TH *quotes*. This is true despite the fact that the quasiquote syntax looks just like a quote. And they're quasi*quotes*. But they really should be quasi*splices*. Specifically,
is the same as
> $(selector blah "...")
where `selector` is the appropriate record selector based on the context where the quasiquote appears.
You are not the first to fall into this trap! Though, I believe this is well documented in the manual.
On Apr 11, 2016, at 9:59 AM, Dominik Bollmann <dominikbollmann at gmail.com> wrote:
> 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|
> <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!
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe