<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">2013/1/23 John Wiegley <span dir="ltr">&lt;<a href="mailto:johnw@fpcomplete.com" target="_blank">johnw@fpcomplete.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">&gt;&gt;&gt;&gt;&gt; John Wiegley &lt;<a href="mailto:johnw@fpcomplete.com">johnw@fpcomplete.com</a>&gt; writes:<br>
<br>
&gt; Never mind, when/unless + left work just fine for this.<br>
<br>
</div>You know, it&#39;s been a humorous day. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


...<br></blockquote><div><br></div><div style>Don&#39;t take it so hard. Trying to reinvent something is always a great exercise and makes you really understand the problem. And it can have interesting results too. One of my university professors once heard about some concept, but didn&#39;t know the details. He tried to derive the concept himself, and he actually invented something different, new and very useful.</div>

<div><br></div><div>... </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
<br>
    &gt;&gt;&gt; let Left x |&gt; y = y; x |&gt; _ = x in Left 1 |&gt; Right 2 |&gt; Right 3<br>
    Right 2            -- same functionality as my Or semigroup<br></blockquote><div><br></div><div style>This strongly reminds me of `mplus` of `Maybe`. The problem is we cannot define a generic instance `MonadPlus Either` because we cannot define `mzero` (but if we restrict the left type, we can achieve this, like in &quot;instance Error e =&gt; MonadPlus (Either e)&quot;).</div>

<div style><br></div><div style>Another possibility how to capture this &quot;Or&quot; behavior is `MonadError`. You could define |&gt; for any instance of `MonadError`, including Either (currently with some restrictions):</div>

<div style><br></div><div style><div>(|&gt;) :: MonadError e m =&gt; m a -&gt; m a -&gt; m a</div><div>x |&gt; y = x `catchError` (const y)</div></div><div style><br></div><div style>  Best regards,</div><div style>  Petr Pudlak</div>

<div> </div></div></div></div>