The FunctorM library

John Meacham john at repetae.net
Wed Mar 23 20:11:21 EST 2005


On Thu, Mar 24, 2005 at 12:58:19AM +0100, Remi Turk wrote:
> On Wed, Mar 23, 2005 at 01:28:28PM -0800, Iavor Diatchki wrote:
> > 
> > > >   3) rename FunctorM class to ForEach
> > I was suggesting here that we rename the method to "forEach" and swap
> > the order of the arguments.   The reason I suggested this is that I
> > find myself writing code like this a lot:
> > 
> > mapM (\x ->
> >   do ... some monadic ...
> >      ... code goes here ...
> > ) xs
> > 
> > this look better in this form:
> > 
> > forEach xs (\x ->
> >   do ... some monadic ...
> >      ... code goes here ...
> > )
> 
> why not just define a normal function: forEach = flip fmapM ?
> Calling the whole class ForEach makes the connection to
> Functor/Monad less clear, and renaming only the method seems
> rather inconsequent to me.

Especially since when working on non-lists, forEach is not at all
obvious.

On a tangent, I was thinking that fsequence is a nice way to commute
monads. of course, not all monads can universally commute with every
other monad, but those that can can be made an instance of FunctorM
giving us a nice reusable routine... 

fsequence :: f (m a) -> m (f a) 

Monads that are an instance of FunctorM can always be pushed
inside of an arbitrary monad. 

Control.Monad.Identity can obviously be made an instance,
can any of the other standard mtl monads?
We should provide those instances. 

        John




-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Libraries mailing list