Template Haskell pattern quotations

Robert Greayer robgreayer at gmail.com
Wed Feb 3 19:47:25 EST 2010

The *splicing* of patterns is considered tricky, see:

Implementing pattern quotations might be less tricky, but I would
imagine to make them useful, you'd have to allow splicing things
*into* them, which requires implementing pattern splicing.   That's my
non-expert take on the issue.

On Wed, Feb 3, 2010 at 7:32 PM, Brad Larsen <brad.larsen at gmail.com> wrote:
> I'll put my question at the very front of this message, and then give
> the context.
> My question:  Are Template Haskell pattern quotations (i.e., [p| ...
> |]) not implemented in GHC because they are rather tricky to
> implement, or because there has not been demand for them?
> And now, the context.
> I am working on an embedded DSL/compiler in Haskell, and I want to
> make use of the recently-much-discussed quasiquoting mechanism to ease
> reading & writing various transformations.
> I read through the quasiquoting paper [1] again and played around with
> some simple examples.  In the paper, Data.Generics is used so that the
> same parser can be used for quasiquoting both expressions and
> patterns.  This requires adding constructors to the ASTs being
> quasiquoted for antiquotations to be possible.
> In my application, I don't anticipate using Data.Generics for parser
> reuse, for a few reasons:
>  * I haven't read the SYB papers, and don't understand how
> Data.Generics or Data.Data work.
>  * My ASTs in some cases involve GADTs with several phantom type
> parameters (is that the right terminology?), and DeriveDataTypeable
> does not work with them.
>  * I don't want to add the extra constructors necessary to support
> antiquotation with the Data.Generics approach.
> So, I'm stuck writing separate ExpQ / PatQ parsers.  (Actually, I can
> write the parser once, if it takes a dictionary of semantic actions as
> a parameter, in which case I only need to write the dictionary of ExpQ
> actions and the dictionary of PatQ actions.)  When writing the ExpQ
> parser, I can use Template Haskell expression quotations, [| ... |].
> When writing the PatQ parser, I have to resort to using the various
> pattern construction combinators, which is unfortunate!  I'd like to
> be able to use pattern quotations instead.
> So, my question once again:  How hard would it be to implement the
> pattern quotations from the Template Haskell paper in GHC?
> Sincerely,
> Brad
> References:
> [1]  Geoffrey B. Mainland.  Why It's Nice to be Quoted:  Quasiquoting
> for Haskell.  <http://www.eecs.harvard.edu/~mainland/ghc-quasiquoting/mainland07quasiquoting.pdf>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

More information about the Glasgow-haskell-users mailing list