<div dir="ltr"><div>exitSuccess :: IO a means that exitSuccess type-checks for any `a`. Your program should typecheck without `void`. I suspect you've got a stray paren.<br><br></div>This prints "Bailing out." and exits zero for me:<br><div><br><pre style="color:#000000;background:#ffffff">module Main where
import System<span style="color:#008c00">.</span>Exit <span style="color:#808030">(</span>exitSuccess<span style="color:#808030">)</span>
import Control<span style="color:#008c00">.</span>Monad <span style="color:#808030">(</span>when<span style="color:#808030">)</span>
main <span style="color:#808030">=</span> do
let condition <span style="color:#808030">=</span> True
when condition <span style="color:#808030">(</span>putStrLn <span style="color:#800000">"</span><span style="color:#0000e6">Bailing out.</span><span style="color:#800000">"</span> <span style="color:#808030">></span><span style="color:#808030">></span> exitSuccess<span style="color:#808030">)</span>
putStrLn <span style="color:#800000">"</span><span style="color:#0000e6">Continuing normally...</span><span style="color:#800000">"<br><br></span></pre><br><div class="gmail_quote"><div dir="ltr">On Tue, 9 Jun 2015 at 08:27 Sumit Sahrawat, Maths & Computing, IIT (BHU) <<a href="mailto:sumit.sahrawat.apm13@iitbhu.ac.in" target="_blank">sumit.sahrawat.apm13@iitbhu.ac.in</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Try `Control.Monad.void`. It is equivalent of adding `>> return ()` to the end of a block.<div><br></div><div>void $ do</div><div> ...</div></div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 June 2015 at 20:55, Vale Cofer-Shabica <span dir="ltr"><<a href="mailto:vale.cofershabica@gmail.com" target="_blank">vale.cofershabica@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all,<br>
<br>
I'm writing a command line program which may need to exit early based<br>
on some condition. Because of the pipeline the program is a part of, I<br>
want to be able to control the exit status when it does terminate. I<br>
can successfully use 'error' to indicate failure, but also want to<br>
exit early with success (or any other status). Here's what I've<br>
managed:<br>
<br>
>import System.Exit (exitSuccess)<br>
>import Control.Monad (when)<br>
<br>
>main = do<br>
<br>
... code to reasonably initialize condition, e.g.:<br>
<br>
> let condition = True<br>
> when condition (putStrLn "Bailing out.")>>exitSuccess>>(return ())<br>
<br>
... program continues<br>
<br>
If I remove ">>(return ())" my code will not typecheck because<br>
"exitSuccess :: IO a". But this looks ugly and smells sufficiently<br>
like a kludge that I presume there is a better way to do it.<br>
<br>
Any suggestions appreciated,<br>
vale<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div><div class="gmail_extra">-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div></div>