Why is there no Foldable instance for Either?
Gabriel Gonzalez
gabriel439 at gmail.com
Thu May 30 21:53:24 CEST 2013
I'm surprised that `Either` does not have a `Foldable` instance of the form:
import Data.Foldable
import Data.Monoid
instance Foldable (Either e) where
foldMap f (Left _) = mempty
foldMap f (Right r) = f r
foldr _ z (Left _) = z
foldr f z (Right r) = f r z
In other words, the above instance would behave like the `Maybe`
`Foldable` instance, treating `Left` in the same way as `Nothing`.
This came up in the context of an issue raised on the `errors` package:
https://github.com/Gabriel439/Haskell-Errors-Library/issues/16
I could provide an orphan instance for `Either` in the `errors` package,
but I wanted to ask if it was possible to incorporate the instance
directly into `Data.Foldable`.
More information about the Libraries
mailing list