[Haskell-beginners] (no subject)

Dennis Raddle dennis.raddle at gmail.com
Mon Sep 3 05:32:13 CEST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120902/58b36638/attachment.htm>


More information about the Beginners mailing list