<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 03/09/12 13:32, Dennis Raddle wrote:
<blockquote
cite="mid:CAKxLvop6q48RC-YWhXS5vgGNu=Zz8yZ1dtVy56kj_cF_LEf+sg@mail.gmail.com"
type="cite">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>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
You probably want to look at Data.Traversable#traverse.<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Tony Morris
<a class="moz-txt-link-freetext" href="http://tmorris.net/">http://tmorris.net/</a>
</pre>
</body>
</html>