[Template-haskell] QuasiQuoting for declarations
Robert Greayer
robgreayer at yahoo.com
Tue Dec 2 00:31:00 EST 2008
Simon Peyton-Jones wrote:
> Meanwhile, I gather you are using quasi-quotes. I’m interested
> to know about applications: what are you using it for?
(I assume this was a general query, hence my reply...)
I'm using it in testing... I have written an an interpreter for a (C-like) language, and quasi-quotation makes the tests for the interpreter read very nicely -- I express a short program in the 'native' language syntax (within a quasi-quotation), and then a few lines of Haskell defining the expected behavior of the program. Without quasiquotation, I'd either have to store the 'native' programs in separate files or build them up as strings (which means, in either case, I could get the syntax wrong and not know it until I run the tests. And the tests are harder to read). It was close to zero work to create the quasi-quoter, since I already had the parser handy. (I did have to enhance it to handle antiquotation, which I needed to make the tests easier to write).
I've visions of using the same technique for expressing tests (queries and expected replies) in the native syntax of a particular server I'm involved in developing, but have not done so yet.
Rob
More information about the template-haskell
mailing list