Instance of `Semigroup (Either a b)` needs to be eventually changed.

박신환 ndospark320 at
Wed May 2 12:44:44 UTC 2018

Now since `base` package version ``, `Monoid` is a subclass of `Semigroup`. And that made `Monoid (Either a b)` instance impossible to exist.

Current (``) instance of `Semigroup (Either a b)` (excluding `stimes`:
-- | @since
instance Semigroup (Either a b) where
    Left _ <> b = b
    a      <> _ = a

No value of `Either a b` can be `mempty`.

This must be eventually changed to:
instance Semigroup a => Semigroup (Either a b) where
    Left a <> Left b = Left (a <> b)
    Left _ <> b      = b
    a      <> _      = a

The former behavior can be made with `Either (Last a) b`.

This makes `Monoid (Either a b)` possible:
instance Monoid a => Monoid (Either a b) where
    mempty = Left mempty

Also `Alternative (Either e)`:
instance Monoid e => Alternative (Either e) where
    empty = mempty
    (<|>) = (<>)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list