QuasiQuoting for declarations

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

QuasiQuoting for declarations

Andrea Vezzosi
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
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

RE: QuasiQuoting for declarations

Simon Peyton Jones

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: [hidden email] [mailto:[hidden email]] On Behalf Of Andrea Vezzosi
Sent: 01 December 2008 08:15
To: [hidden email]
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
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

Re: QuasiQuoting for declarations

Robert Greayer
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
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell
Reply | Threaded
Open this post in threaded view
|

Re: QuasiQuoting for declarations

Reiner Pope
On Tue, Dec 2, 2008 at 4:31 PM, Robert Greayer <[hidden email]> 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
> [hidden email]
> 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
_______________________________________________
template-haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/template-haskell