concatMap generalizes to msumMap?

What is the name of the monadic generalization of concatMap? In which lib is it located? -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com

On Mon, May 16, 2005 at 02:57:42PM -0400, S. Alexander Jacobson wrote:
What is the name of the monadic generalization of concatMap?
(=<<) or simply (>>=) if you don't care about argument order. Probably not what you are after?
In which lib is it located?
The former is in module Monad, the latter in Prelude. Best regards Tomasz

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 In contrast <<= has type (=<<) :: (Monad m) => (a -> m b) -> m a -> m b -Alex- ______________________________________________________________ S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com On Mon, 16 May 2005, Tomasz Zielonka wrote:
On Mon, May 16, 2005 at 02:57:42PM -0400, S. Alexander Jacobson wrote:
What is the name of the monadic generalization of concatMap?
(=<<) or simply (>>=) if you don't care about argument order. Probably not what you are after?
In which lib is it located?
The former is in module Monad, the latter in Prelude.
Best regards Tomasz
** CRM114 Whitelisted by: tomasz.zielonka@gmail.com **

On Mon, May 16, 2005 at 03:20:25PM -0400, S. Alexander Jacobson wrote:
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
In contrast <<= has type
(=<<) :: (Monad m) => (a -> m b) -> m a -> m b
However: Prelude Control.Monad> concatMap (\i -> [i,i]) [1,2,3] [1,1,2,2,3,3] Prelude Control.Monad> (=<<) (\i -> [i,i]) [1,2,3] [1,1,2,2,3,3] You could define concatMap as =<< concatMap :: (a -> [b]) -> [a] -> [b] concatMap = (=<<) I guess you don't want it that general. (=<<) for IO doesn't resemble concatMap. Best regards Tomasz

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
participants (3)
-
David Menendez
-
S. Alexander Jacobson
-
Tomasz Zielonka