[Haskell-cafe] Template Haskell antiquotation in user-defined quasiquoters

Antoine Latter aslatter at gmail.com
Fri May 25 22:46:00 CEST 2012

On Fri, May 25, 2012 at 2:51 PM, Sam Lindley <Sam.Lindley at ed.ac.uk> wrote:
> Template Haskell supports antiquotation for built-in quasiquotes, e.g.:
>  [| \x -> x + $([|3 * 4|]) |]
> However, as far as I can tell, there is no way of supporting antiquotation
> in user-defined quasiquoters, because the only way to specify a new
> quasiquoter is through a quoteExp function of type String -> Q Exp. Of
> course, it is perfectly possible to write a parser for some fragment of
> Haskell inside your quoteExp function, but that seems crazy given that
> Template Haskell or rather GHC already implements a parser for the whole
> language.
> I know about Language.Haskell.Exts.Parser in haskell-src-exts, which
> provides parseExp :: String -> ParseResult Exp, but that Exp is a different
> type to the one provided by Template
> Haskell.<http://hackage.haskell.org/packages/archive/haskell-src-exts/1.9.0/doc/html/Language-Haskell-Exts-Syntax.html#t:Exp>
> I'm also aware of Dominic Orchard's syntax-trees package, which supports
> converting between the two representations using a cunning hack that
> pretty-prints the haskell-src-exts representation to a string and uses
> Template Haskell to parse it back.
> Is there a saner way of simulating antiquotation in user-defined
> quasiquoters?

Have you looked at:


The might help you pull something together.


> Sam
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list