Collecting values from Functors?
Tomasz Zielonka
t.zielonka@students.mimuw.edu.pl
Wed, 4 Jun 2003 20:40:57 +0200
On Wed, Jun 04, 2003 at 08:38:29PM +0200, Tomasz Zielonka wrote:
> On Wed, Jun 04, 2003 at 11:15:30AM -0700, Hal Daume III wrote:
> > > I'm trying to figure if there's any way I can use (say) monads to collect
> > > values from a Functor.
> > >
> > > For example, suppose I have a tree of some values that supports fmap, is
> > > there any way I can use the fmap function to collect a list of all the node
> > > values?
> >
> > No, you need a fold to do that.
>
> Or a variant of Functor constructor class that I have proposed some time
> ago on comp.lang.functional:
>
> class FunctorM t where
> fmapM :: Monad m => (a -> m b) -> (t a -> m (t b))
> fmapM_ :: Monad m => (a -> m b) -> (t a -> m ())
> fmapM_ f t = fmapM f t >> return ()
>
> instance FunctorM [] where
> fmapM = mapM
> fmapM_ = mapM_
I am sorry, I misunderstood the problem.
Best regards,
Tom
--
.signature: Too many levels of symbolic links