<div>Hrmm. This should probably be made consistent with the MonadPlus instance for IO, so</div>
<div> </div>
<div>&gt; empty = ioError (userError &quot;mzero&quot;)<br></div>
<div>Otherwse, I&#39;m surprised this isn&#39;t already in the standard library. </div>
<div> </div>
<div>I&#39;d suggest submitting it to libraries@.</div>
<div> </div>
<div>-Edward Kmett<br></div>
<div class="gmail_quote">On Thu, Jul 9, 2009 at 9:27 AM, Cristiano Paris <span dir="ltr">&lt;<a href="mailto:cristiano.paris@gmail.com">cristiano.paris@gmail.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">As a joke, I wrote an instance of Alternative for IO actions: 
<div><br></div>
<div>
<div>{-# LANGUAGE ScopedTypeVariables #-}</div>
<div>module Main where</div>
<div><br></div>
<div>import Control.Applicative</div>
<div>import Control.Exception</div>
<div><br></div>
<div>instance Alternative IO where</div>
<div>  empty = undefined</div>
<div>  x &lt;|&gt; y = handle (\ (_ :: SomeException) -&gt; y) x</div>
<div><br></div>
<div>This would allow to write IO code which failsafes to a value if the previous computation failed, i.e.:</div>
<div><br></div>
<div>
<div>*Main Control.Applicative&gt; undefined &lt;|&gt; print &quot;Hello&quot;</div>
<div>&quot;Hello&quot;</div>
<div>*Main Control.Applicative&gt; print &quot;Hello&quot; &lt;|&gt; undefined</div>
<div>&quot;Hello&quot;</div>
<div><br></div>
<div>It seems a neat way to catch exception in some scenarios. What do you think? Why is not Alternative IO defined in Control.Applicative?</div></div>
<div><br></div>
<div>Thanks,</div>
<div><br></div><font color="#888888">
<div>Cristiano</div></font></div><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" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>