This rewrite changes the order of execution.  The old version did all of the putDirs and then all of the renameFile calls.  The new one interleaves putDirs & renameFile calls.  In general, ">>" is not commutative, though in this case you may be as happy with either order.  - Conal
<br><br><div><span class="gmail_quote">On 12/12/06, <b class="gmail_sendername">Bryan Burgers</b> &lt;<a href="mailto:bryan.burgers@gmail.com">bryan.burgers@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 12/12/06, Louis J Scoras &lt;<a href="mailto:louis.j.scoras@gmail.com">louis.j.scoras@gmail.com</a>&gt; wrote:<br>&gt; I have some IO actions that I want to map over a list of pairs --<br>&gt; these are just directory names and their down-cased versions.&nbsp;&nbsp;It
<br>&gt; wasn't difficult to actually get the right behavior by just doing mapM<br>&gt; twice.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -- putDirs just outputs something like &quot;mv fst snd&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; mapM_ putDirs pairs<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; mapM_ (uncurry renameFile) pairs
<br>&gt;<br>&gt; This bothered me though, because I suspected that this could be done<br>&gt; in one pass.&nbsp;&nbsp;Naively I proceeded to this.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; mapM_ (putDirs &gt;&gt; (uncurry renameFile)) pairs<br>&gt;<br>&gt; Which didn't work.&nbsp;&nbsp;I thought about it a little more before realizing
<br>&gt; that putDirs wouldn't get any parameters this way: I needed some way<br>&gt; to distribute the pair over both operations.&nbsp;&nbsp;Here's the higher-order<br>&gt; function I needed:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; foo h f g i = h (f i) (g i)
<br>&gt;<br>&gt; which could then be curried and we get:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; mapM_ (foo (&gt;&gt;) putDirs $ uncurry renameFile) pairs<br>&gt;<br>&gt; Works great.&nbsp;&nbsp;So my question: is there a established name for foo?<br>
&gt; What about foo partially applied to (&gt;&gt;)?&nbsp;&nbsp;This was a fun exercise,<br>&gt; but I'd like to use the standard implementations if they exist.<br><br>Before we get too far down the obfuscation road, I'd like to offer
<br>what I think is more readable than a liftM2 solution:<br><br>&nbsp;&nbsp; mapM_ (\p -&gt; putDirs p &gt;&gt; uncurry renameFile p) pairs<br><br>I haven't tested it, but I hope that does the same thing. To me, this<br>explicitely shows what each is doing, moreso than with a point-free
<br>'foo' combinator.<br><br>The way my mind worked to get to this solution:<br><br>&nbsp;&nbsp; mapM_ putDirs pairs<br>&nbsp;&nbsp; mapM_ (uncurry renameFile) pairs<br><br> ==&gt;<br><br>&nbsp;&nbsp; mapM_ (\p -&gt; putDirs p) pairs<br>&nbsp;&nbsp; mapM_ (\p -&gt; uncurry renameFile p) pairs
<br><br> ==&gt;<br><br>&nbsp;&nbsp; mapM_ (\p -&gt; putDirs p &gt;&gt; uncurry renameFile p) pairs<br><br>Is that a reasonable solution?<br><br>Bryan Burgers<br>_______________________________________________<br>Haskell-Cafe mailing list
<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></blockquote></div><br>