
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. M.map has this type: M.map :: (Ord k) => (a -> b) -> Map k a -> Map k b However, I want to use a mapping function that has type (Monad m) => a -> m b (i.e. errors could be thrown during the computation, a log could be written, etc) I wrote the following. Any comments on this way of doing things? mapMapM :: (Monad m, Ord k) => (a -> m b) -> Map k a -> m (Map k b) mapMapM g mapIn = do let h (k,a) = do b <- g a return (k,b) y <- mapM h (M.toAscList mapIn) return $ M.fromAscList y

On 03/09/12 13:32, Dennis Raddle wrote:
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.
M.map has this type:
M.map :: (Ord k) => (a -> b) -> Map k a -> Map k b
However, I want to use a mapping function that has type
(Monad m) => a -> m b
(i.e. errors could be thrown during the computation, a log could be written, etc)
I wrote the following. Any comments on this way of doing things?
mapMapM :: (Monad m, Ord k) => (a -> m b) -> Map k a -> m (Map k b) mapMapM g mapIn = do let h (k,a) = do b <- g a return (k,b) y <- mapM h (M.toAscList mapIn) return $ M.fromAscList y
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
You probably want to look at Data.Traversable#traverse. -- Tony Morris http://tmorris.net/
participants (2)
-
Dennis Raddle
-
Tony Morris