[Haskell-cafe] concatMap generalizes to msumMap?

Tomasz Zielonka tomasz.zielonka at gmail.com
Mon May 16 16:38:40 EDT 2005


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


More information about the Haskell-Cafe mailing list