I wanted to run the map function from Data.Map, let's call it M.map, but inside a monad transformer stack including the Error monad. <br><br>M.map has this type:<br><br>M.map :: (Ord k) => (a -> b) -> Map k a -> Map k b<br>
<br>However, I want to use a mapping function that has type<br><br>(Monad m) => a -> m b<br><br>(i.e. errors could be thrown during the computation, a log could be written, etc)<br><br>I wrote the following. Any comments on this way of doing things?<br>
<br>mapMapM :: (Monad m, Ord k) => (a -> m b) -> Map k a -> m (Map k b)<br>mapMapM g mapIn = do<br> let h (k,a) = do<br> b <- g a<br> return (k,b)<br> y <- mapM h (M.toAscList mapIn)<br> return $ M.fromAscList y<br>
<br>