Andrea Vezzosi | 1 Dec 2008 09:14
Picon
Gravatar

QuasiQuoting for declarations

Currently quasiquoting is limited to patterns and expressions, are there any problems in extending it to declarations? we already have [d| ... |] and toplevel splices afterall.

_______________________________________________
template-haskell mailing list
template-haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/template-haskell
Simon Peyton-Jones | 1 Dec 2008 16:09
Picon
Favicon
Gravatar

RE: QuasiQuoting for declarations

I think there is no difficulty in principle.

 

In the HsExpr you’ll see the constructors

                HsSpliceE

                HsQuasiQuoteE

The former is run by the type checker; thelatter by the renamer.

 

To fulfil your hope, we’d need to add a new constructor to HsDecls.SpliceDecl.  At the moment it just has

                SpliceDecl

and we’d add

                QuasiQuoteDecl

 

After that I think the rest would follow. If someone feels like taking it up, I’d be glad to help.  For a start, make a Trac feature request and dump this thread into it.

 

Meanwhile, I gather you are using quasi-quotes.  I’m interested to know about applications: what are you using it for?


Simon

 

From: template-haskell-bounces <at> haskell.org [mailto:template-haskell-bounces <at> haskell.org] On Behalf Of Andrea Vezzosi
Sent: 01 December 2008 08:15
To: template-haskell <at> haskell.org
Subject: [Template-haskell] QuasiQuoting for declarations

 

Currently quasiquoting is limited to patterns and expressions, are there any problems in extending it to declarations? we already have [d| ... |] and toplevel splices afterall.

_______________________________________________
template-haskell mailing list
template-haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/template-haskell
Robert Greayer | 2 Dec 2008 06:31
Picon
Favicon

Re: QuasiQuoting for declarations

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

      
Reiner Pope | 3 Dec 2008 12:46
Picon
Gravatar

Re: QuasiQuoting for declarations

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

Gmane