[Template-haskell] QuasiQuoting for declarations

Reiner Pope reiner.pope at gmail.com
Wed Dec 3 06:46:41 EST 2008


On Tue, Dec 2, 2008 at 4:31 PM, Robert Greayer <robgreayer at yahoo.com> wrote:
> 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
>
>
>
>
> _______________________________________________
> template-haskell mailing list
> template-haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/template-haskell
>

I'm using quasiquoting to generate statically-sized vectors and
matrices. The vectors and matrices are abstract datatypes, so
quasiquoting gives a method for statically-checked construction, and
also potentially allows more efficient construction than, say,
converting to and from lists.

Reiner


More information about the template-haskell mailing list