<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">2013/1/23 John Wiegley <span dir="ltr"><<a href="mailto:johnw@fpcomplete.com" target="_blank">johnw@fpcomplete.com</a>></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">>>>>> John Wiegley <<a href="mailto:johnw@fpcomplete.com">johnw@fpcomplete.com</a>> writes:<br>
<br>
> Never mind, when/unless + left work just fine for this.<br>
<br>
</div>You know, it'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'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'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>
>>> let Left x |> y = y; x |> _ = x in Left 1 |> Right 2 |> 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 "instance Error e => MonadPlus (Either e)").</div>
<div style><br></div><div style>Another possibility how to capture this "Or" behavior is `MonadError`. You could define |> for any instance of `MonadError`, including Either (currently with some restrictions):</div>
<div style><br></div><div style><div>(|>) :: MonadError e m => m a -> m a -> m a</div><div>x |> 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>