Hi all,

while coding recently I came across the need for
a strict mapM (that I indicidently use for m = MaybeT IO).

I implementented this with the following simple code
(it works for my use case):

mapM' :: Monad m => (a-> m b) -> [a] -> m [b]
mapM' _ []     = return []
mapM' f (x:xs) = do y  <- f x
                    ys <- y `seq` mapM' f xs
                    return (y:ys)

Now a couple of questions:

1. is it so "rare" to need such a beast? Why there isn't anything
   like that in standard libraries?
2. Is my implementation correct?
3. I've seen that mapM is implemented in base via sequence
   (which is in turn based on foldr). Is that any specific
   reason to prefer base implementation to mine?

Thanks!
Pao

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to