<div>Thank you very much for the help. Good tips for improving my code design.</div>
<div>I'm new to sequence, mapM, and mapM_; I'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"><<a href="mailto:steffen.siering@googlemail.com">steffen.siering@googlemail.com</a>></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 "sequence"<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 <<a href="mailto:ps.hask...@gmail.com">ps.hask...@gmail.com</a>> wrote:<br>> I am able to use System.Cmd (system) to invoke a shell command<br>> and interpret the results.<br>
><br>> Please see the code below that works okay for one such command.<br>> (I invoke a program, passing two args.)<br>><br>> I am wondering how to generalize this to do likewise for a<br>> series of commands, where the varying args (filenames, in this<br>
> case) are in a list ('inOutLeafs').<br>><br>> I will also want to accumulate some results; probably just a<br>> failure count at this time.<br>><br>> Any advice or pointers to examples would be much appreciated.<br>
><br>> Thanks in advance,<br>> -- Peter<br>><br>><br>><br>><br>><br>><br>><br>><br>><br>> > run :: ... -> IO (Int) -- will return a fail count<br>> > run<br>> > -- some args to this function here...<br>
> > = do<br>> > -- ... set up: inputLeafs, outputLeafs, etc.<br>><br>> > -- zip two lists of filenames:<br>> > let inOutLeafs = zip inputLeafs outputLeafs<br>><br>> > -- the first pair for the first command:<br>
> > let (inFile1,outFile1) = head inOutLeafs<br>><br>> > -- build 1st command using 1st pair of filenames:<br>> > let cmd1 = ...<br>><br>> > exitCode <- system cmd1<br>
> > case (exitCode) of<br>> > ExitSuccess -> do<br>> > putStrLn $ "-- OK."<br>> > return 0<br>> > ExitFailure failCnt -> do<br>
> > putStrLn $ "-- Failed: " ++ show failCnt<br>> > return 1<br>><br></div></div>> _______________________________________________<br>> Haskell-Cafe mailing list<br>> 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>