Template Haskell pattern quotations
brad.larsen at gmail.com
Wed Feb 3 19:32:59 EST 2010
I'll put my question at the very front of this message, and then give
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  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?
 Geoffrey B. Mainland. Why It's Nice to be Quoted: Quasiquoting
for Haskell. <http://www.eecs.harvard.edu/~mainland/ghc-quasiquoting/mainland07quasiquoting.pdf>
More information about the Glasgow-haskell-users