Newtype wrappers in hsSyn

Neil Mitchell ndmitchell at gmail.com
Wed Jan 27 15:06:21 EST 2010


Hi

> I know Uniplate.  But there are two issues:
>
>  1. SYB will start using the table trick soon from what I hear, so I hope it won't be too slow.

That would be cool - although I do wonder how it can be done with the
very general type of everywhere/everything. If you restrict the types
(like Uniplate) then it's not massively hard, but you do need to know
statically. For whoever is implementing this trick, I recommend they
take what they can from Data/Generics/Uniplate/Data.hs - writing a hit
table implementation isn't trivial, and I've messed it up several
times.

>  2. How do I customise traversals based on context information?  In SYB I use extQ, how would I do the same in Uniplate?  E.g.,
> if I wanted to gather all Id's but not those occurring inside SyntaxExpr (which are filled out by the renamer in order to describe
> which `>>=` to use and other things.)

Assuming you do make the change to use a newtype, then:

childrenBi . transformBi (const noSyntaxExpr)

You've also got "descend" which can often be used to propagate context
downwards.

> In any case, one would probably want both.  If Uniplate/Biplate is enough, it's probably easier to use, but for more flexibility
> we want the option to use SYB.

Uniplate is great when it works, and I find it works for removing
boilerplate traversals/queries in nearly all cases. But I always have
SYB to fall back on, which is much more powerful.

Thanks, Neil



More information about the Cvs-ghc mailing list