Add everywhereM' to Data.Generics.Schemes

Hello, as an analogue to everywhere', I suggest adding everywhereM' to Data.Generics.Schemes. The implementation would be everywhereM' :: Monad m => GenericM m -> GenericM m everywhereM' f x = do { x' <- f x; gmapM (everywhereM' f) x' } Best wishes, Maciej

Hi Maciej, Data.Generics.Schemes is now on the syb package, and I'm its maintainer. But I'm not so sure it is wise to start adding more traversal schemes of this form, since there might be many of them: if we include everywhereM', we certainly have to include the bottom-up everywhereM too. Then there are the possible Applicative variants, etc... In general, since these traversal functions are small and everywhere and everywhere' already show the pattern of how to write them, maybe it's best that they are defined by the user, unless there is some general consensus that they would be widely useful. Cheers, Pedro On Mon, Apr 12, 2010 at 20:56, Maciej Podgurski < maciej.podgurski@googlemail.com> wrote:
Hello,
as an analogue to everywhere', I suggest adding everywhereM' to Data.Generics.Schemes. The implementation would be
everywhereM' :: Monad m => GenericM m -> GenericM m everywhereM' f x = do { x' <- f x; gmapM (everywhereM' f) x' }
Best wishes,
Maciej _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

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
On Mon, Apr 12, 2010 at 8:35 PM, José Pedro Magalhães
Hi Maciej,
Data.Generics.Schemes is now on the syb package, and I'm its maintainer. But I'm not so sure it is wise to start adding more traversal schemes of this form, since there might be many of them: if we include everywhereM', we certainly have to include the bottom-up everywhereM too. Then there are the possible Applicative variants, etc...
In general, since these traversal functions are small and everywhere and everywhere' already show the pattern of how to write them, maybe it's best that they are defined by the user, unless there is some general consensus that they would be widely useful.
Cheers, Pedro
On Mon, Apr 12, 2010 at 20:56, Maciej Podgurski
wrote: Hello,
as an analogue to everywhere', I suggest adding everywhereM' to Data.Generics.Schemes. The implementation would be
everywhereM' :: Monad m => GenericM m -> GenericM m everywhereM' f x = do { x' <- f x; gmapM (everywhereM' f) x' }
Best wishes,
Maciej _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Generics mailing list Generics@haskell.org http://www.haskell.org/mailman/listinfo/generics

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

Hi Matthias, I started writing an email, but decided a blog post would be a better place to put down my thoughts on everywhere': http://neilmitchell.blogspot.com/2010/04/dangerous-primes-why-uniplate-doesn...
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.
It's possible to use everywhere' correctly, but not trivial. Using descend it's trivial to get right, which is much safer. Read the blog post for my best thoughts why.
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?
I recommend to everyone they drop whatever generics solution they are using and switch to Uniplate :-) [If Uniplate can express what you want - it's one of the least powerful generics libraries - but gets almost all the common uses] I think using descend (from Uniplate) or compos (from Compos paper), or writing a descend/compos operator for SYB, is the right way to go. It's a nicer primitive, and it's perfectly definable in most generics frameworks. I think everywhere' is a bad primitive in any generics framework. Thanks, Neil
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
participants (4)
-
José Pedro Magalhães
-
Maciej Podgurski
-
Matthias Reisner
-
Neil Mitchell