<div>Thank you very much for the help. Good tips for improving my code design.</div>
<div>I&#39;m new to sequence, mapM, and mapM_; I&#39;ve seen mapM a lot while reading code and wanted to learn it; now I have a reason! Thanks.</div>
<div>-- Peter</div><br><br>
<div class="gmail_quote">On Thu, Nov 18, 2010 at 5:40 AM, steffen <span dir="ltr">&lt;<a href="mailto:steffen.siering@googlemail.com">steffen.siering@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">1. Write one routine, which does all the work for just one command.<br>2. use sequence or mapM, mapM_ from Control.Monad (depending on your<br>
needs),<br>  to apply your function to a list of commands<br><br>accumulating results you may want to process the output of &quot;sequence&quot;<br>or use the WriterT Monad Transformer.<br><br>If you want to stop processing the rest of the list on error, either<br>
write a recursive function yourself or use foldM or use ErrorT Monad<br>Transformer.<br>
<div>
<div></div>
<div class="h5"><br>On Nov 18, 3:03 am, Peter Schmitz &lt;<a href="mailto:ps.hask...@gmail.com">ps.hask...@gmail.com</a>&gt; wrote:<br>&gt; I am able to use System.Cmd (system) to invoke a shell command<br>&gt; and interpret the results.<br>
&gt;<br>&gt; Please see the code below that works okay for one such command.<br>&gt; (I invoke a program, passing two args.)<br>&gt;<br>&gt; I am wondering how to generalize this to do likewise for a<br>&gt; series of commands, where the varying args (filenames, in this<br>
&gt; case) are in a list (&#39;inOutLeafs&#39;).<br>&gt;<br>&gt; I will also want to accumulate some results; probably just a<br>&gt; failure count at this time.<br>&gt;<br>&gt; Any advice or pointers to examples would be much appreciated.<br>
&gt;<br>&gt; Thanks in advance,<br>&gt; -- Peter<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; &gt; run :: ... -&gt; IO (Int)    -- will return a fail count<br>&gt; &gt; run<br>&gt; &gt;    -- some args to this function here...<br>
&gt; &gt;    = do<br>&gt; &gt;       -- ... set up: inputLeafs, outputLeafs, etc.<br>&gt;<br>&gt; &gt;       -- zip two lists of filenames:<br>&gt; &gt;       let inOutLeafs = zip inputLeafs outputLeafs<br>&gt;<br>&gt; &gt;       -- the first pair for the first command:<br>
&gt; &gt;       let (inFile1,outFile1) = head inOutLeafs<br>&gt;<br>&gt; &gt;       -- build 1st command using 1st pair of filenames:<br>&gt; &gt;       let cmd1 = ...<br>&gt;<br>&gt; &gt;       exitCode &lt;- system cmd1<br>
&gt; &gt;       case (exitCode) of<br>&gt; &gt;          ExitSuccess -&gt; do<br>&gt; &gt;             putStrLn $ &quot;-- OK.&quot;<br>&gt; &gt;             return 0<br>&gt; &gt;          ExitFailure failCnt -&gt; do<br>
&gt; &gt;             putStrLn $ &quot;-- Failed: &quot; ++ show failCnt<br>&gt; &gt;             return 1<br>&gt;<br></div></div>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; Haskell-C...@haskell.orghttp://<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">www.haskell.org/mailman/listinfo/haskell-cafe</a><br>

<div>
<div></div>
<div class="h5">_______________________________________________<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" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>