[Haskell-cafe] Template Haskell antiquotation in user-defined quasiquoters
Sam Lindley
Sam.Lindley at ed.ac.uk
Fri May 25 21:51:38 CEST 2012
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?
Sam
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the Haskell-Cafe
mailing list