[Hs-Generics] Re: Add everywhereM' to Data.Generics.Schemes

Matthias Reisner matthias.reisner at googlemail.com
Sun Apr 18 17:04:48 EDT 2010


Hi Neil,

for a library I use a version of everywhereM', similar to Maciej's one, 
too. I need to traverse an AST in top-down manner and replace some terms 
by others, like in the following simplified example:

    B (A (B x)) -> f x
    A (B x)     -> g x
    B x         -> h x
    x           -> x

Here a bottom-up traversal would produce wrong results. (The functions 
f, g, h don't make use of A and B, so I didn't think about if 
everywhereM' would completely fail if they would.)

This said, if I understand your last post correctly, the use of 
everywhereM' would be a bug here in your eyes. Do you agree? Because I 
don't think so. I haven't done a lot of testing yet, but each case where 
a replacement has to be performed works as expected. And even if it's 
not a bug, do you suggest to drop everywhereM' and use uniplate instead, 
just to play it safe?


Regards,

Matthias


Am 18.04.2010 09:38 schrieb Neil Mitchell:
> Hi,
>
> I thought a lot about everywhere' when writing uniplate. I have an
> equivalent of everywhere (transform), but no transform'. In the end I
> decided that it was virtually impossible to use everywhere' correctly,
> and that almost every call of everywhere' was either somewhere an
> everywhere would have worked equally well, or a bug. I then went
> through all the Haskell source code I could find, found about 6 calls
> to everywhere', and all of them would have performed the same job as
> everywhere.
>
> So, my suggestion is that everywhereM' probably isn't very useful, but
> descend/descendM (or compos) is a useful top-down traversal scheme.
>
> Thanks, Neil



More information about the Libraries mailing list