+1, I wanted this recently. <div><br></div><div>Erik<span></span><br><br>On Thursday, May 30, 2013, Shachaf Ben-Kiki  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thu, May 30, 2013 at 12:53 PM, Gabriel Gonzalez &lt;<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;gabriel439@gmail.com&#39;)">gabriel439@gmail.com</a>&gt; wrote:<br>
&gt; I&#39;m surprised that `Either` does not have a `Foldable` instance of the form:<br>
&gt;<br>
&gt;     import Data.Foldable<br>
&gt;     import Data.Monoid<br>
&gt;<br>
&gt;     instance Foldable (Either e) where<br>
&gt;         foldMap f (Left  _) = mempty<br>
&gt;         foldMap f (Right r) = f r<br>
&gt;<br>
&gt;         foldr _ z (Left  _) = z<br>
&gt;         foldr f z (Right r) = f r z<br>
&gt;<br>
&gt; In other words, the above instance would behave like the `Maybe` `Foldable`<br>
&gt; instance, treating `Left` in the same way as `Nothing`.<br>
&gt;<br>
&gt; This came up in the context of an issue raised on the `errors` package:<br>
&gt;<br>
&gt; <a href="https://github.com/Gabriel439/Haskell-Errors-Library/issues/16" target="_blank">https://github.com/Gabriel439/Haskell-Errors-Library/issues/16</a><br>
&gt;<br>
&gt; I could provide an orphan instance for `Either` in the `errors` package, but<br>
&gt; I wanted to ask if it was possible to incorporate the instance directly into<br>
&gt; `Data.Foldable`.<br>
&gt;<br>
<br>
This instance should exist. There&#39;s been a couple of discussion on<br>
libraries@ before. One of them is at<br>
&lt;<a href="http://www.haskell.org/pipermail/libraries/2012-July/018246.html" target="_blank">http://www.haskell.org/pipermail/libraries/2012-July/018246.html</a>&gt;.<br>
<br>
I wrote a patch for base at one point --<br>
&lt;<a href="http://shachaf.net/0001-Add-Foldable-and-Traversable-instances-for-Either-e-.patch" target="_blank">http://shachaf.net/0001-Add-Foldable-and-Traversable-instances-for-Either-e-.patch</a>&gt;<br>
-- but didn&#39;t go through the rest of the process at the time.<br>
<br>
Right now `lens` has an orphan instance for this, by the way.<br>
<br>
    Shachaf<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;Libraries@haskell.org&#39;)">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</blockquote></div>