+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 <<a href="javascript:;" onclick="_e(event, 'cvml', 'gabriel439@gmail.com')">gabriel439@gmail.com</a>> wrote:<br>
> I'm surprised that `Either` does not have a `Foldable` instance of the form:<br>
><br>
> import Data.Foldable<br>
> import Data.Monoid<br>
><br>
> instance Foldable (Either e) where<br>
> foldMap f (Left _) = mempty<br>
> foldMap f (Right r) = f r<br>
><br>
> foldr _ z (Left _) = z<br>
> foldr f z (Right r) = f r z<br>
><br>
> In other words, the above instance would behave like the `Maybe` `Foldable`<br>
> instance, treating `Left` in the same way as `Nothing`.<br>
><br>
> This came up in the context of an issue raised on the `errors` package:<br>
><br>
> <a href="https://github.com/Gabriel439/Haskell-Errors-Library/issues/16" target="_blank">https://github.com/Gabriel439/Haskell-Errors-Library/issues/16</a><br>
><br>
> I could provide an orphan instance for `Either` in the `errors` package, but<br>
> I wanted to ask if it was possible to incorporate the instance directly into<br>
> `Data.Foldable`.<br>
><br>
<br>
This instance should exist. There's been a couple of discussion on<br>
libraries@ before. One of them is at<br>
<<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>>.<br>
<br>
I wrote a patch for base at one point --<br>
<<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>><br>
-- but didn'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, 'cvml', 'Libraries@haskell.org')">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>