Hi Renah,

don't know if I understood correctly, but this might help:

Long version:

fun' :: MonadIO m => (a -> m [b]) -> [a] -> m [b]
fun' f cs = do
  results <- mapM f cs
  let merged = concat results
  return merged


Shorter version with fmap:

import  Control.Applicative ((<$>))

fun :: (MonadIO m, Functor m) => (a -> m [b]) -> [a] -> m [b]
fun f cs = concat <$> mapM f cs


Best regards,

vlatko

-------- Original Message --------
Subject: [Haskell-beginners] combine concatMap and mapM
From: Renah Scarowsky <renahs@suite-sol.com>
To: beginners@haskell.org <beginners@haskell.org>
Date: 17.02.2014 11:38


Hi,

 

How would I combine the functionalities of concatMap and mapM to define a function like:

Monad m => (a  -> m [b]) -> [a] -> m [b]

 

I need to create a recursive function within the IO monad which results in a list of the original type.

So something like:

goX :: MonadIO m => x -> m [x]

goX = do

….

x includes within it a list of xs, let's call it (children x)

I need to call goX on each of the children and get a modified list of children as result
ys <- ?

return $ x { children = ys } : zs

 

 

Thanks,

 

Renah Scarowsky

Suite Solutions

Create>Manage>Deploy

http://www.suite-sol.com

 

 



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners