Remove Semigroup and Monoid instances for Either

Andrew Martin andrew.thaddeus at
Thu May 24 13:56:48 UTC 2018

The Semigroup and Monoid instances for Either have surprising behaviors.
Currently, the Semigroup instance is written as:

instance Semigroup (Either a b) where
  Left _ <> b = b
  a <> _ = a

One would expect that the Semigroup instances for `Maybe a` and `Either ()
a` would have the same behaviors, but they don't. We could do better with:

instance Semigroup b => Semigroup (Either a b) where
  (<>) = liftA2 (<>)

And now the behaviors match. This generalizes the old Semigroup instance,
which could be recovered with `Either a (Data.Semigroup.First b)`.

For now, all I'm proposing is removing the existing Semigroup and Monoid
instances for Either. I do not believe that new instances should be given
immidiately, since that would be the worst kind of breaking change: one
that the compiler does not error on.

-Andrew Thaddeus Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list