Proposal: Add concatMapM function (#2042)
Ross Paterson
ross at soi.city.ac.uk
Wed Jan 16 05:29:53 EST 2008
On Tue, Jan 15, 2008 at 08:31:48PM +0000, Conor McBride wrote:
> And now we're home!
>
> > parpSplat ::
> > (Applicative parp, Foldable f, Monoid splat) =>
> > (x -> parp splat) -> f x -> parp splat
> > parpSplat = ala AMonoid foldMap
> > -- modulo AMonoid aMonoid foldMap
Unfolding these definitions, a shorter (but less scenic) route to this
particular destination is:
foldMapM :: (Monad m, Foldable t, Monoid v) => (a -> m v) -> t a -> m v
foldMapM f = Data.Foldable.foldr mappend_f (return mempty)
where mappend_f x y = liftM2 mappend (f x) y
foldMapA :: (Applicative f, Foldable t, Monoid v) => (a -> f v) -> t a -> f v
foldMapA f = Data.Foldable.foldr mappend_f (pure mempty)
where mappend_f x y = mappend <$> f x <*> y
More information about the Libraries
mailing list