[Template-haskell] The ':' operation with patterns ?

Simon Peyton-Jones simonpj@microsoft.com
Thu, 6 Feb 2003 17:23:42 -0000


Sean says :

| Firstly, if we defined
|=20
| pcons :: Patt -> Patt -> Patt
| pcons x xs =3D [p| $x : $xs |]
|=20
| as per the Template Haskell paper we get the error message
|=20
| MkZip.hs:23: Parse error in pattern

Indeed, pattern splices are not implemented, nor are pattern quotes.
Why not?  Below is a message I sent to Tim about this.  I'd be
interested to know the thoughts of other TH folk.

When I sent my message to Tim I was thinking about pattern splices in an
expression context, thus (\ $p -> e).  But Sean's difficulty shows how
useful pattern quotes and splices might be to build bigger patterns: [p|
$x : $xs |].  Indeed, I hadn't thought of that.

I suppose it might be possible to allow pattern splices inside pattern
quotes.  Seems a bit weird and ad-hoc, though.  I don't know how hard it
would be to implement.

Simon