[Haskell-cafe] concatMap generalizes to msumMap?

David Menendez zednenem at psualum.com
Mon May 16 18:52:38 EDT 2005


S. Alexander Jacobson writes:

> I don't think that is right.  concatMap has definition
> 
>    concatMap :: (a -> [b]) -> [a] -> [b]
>    concatMap f xs = concat $ map f xs
> 
> Therefore:
> 
>    msumMap :: (MonadPlus m) => (a1 -> m a) -> [a1] -> m a
>    msumMap f list = msum $ fmap f list

Assuming your goal is to generalize by replacing (++) with mplus, you
want this:

    msumMap f = foldr (mplus . f) mzero

It isn't in the standard libraries, so you'll have to define it
yourself.
-- 
David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
<http://www.eyrie.org/~zednenem>      |        of thermodynamics!"


More information about the Haskell-Cafe mailing list