Instance of `Semigroup (Either a b)` needs to be eventually changed.
박신환
ndospark320 at naver.com
Wed May 2 12:44:44 UTC 2018
Now since `base` package version `4.11.0.0`, `Monoid` is a subclass of `Semigroup`. And that made `Monoid (Either a b)` instance impossible to exist.
Current (`4.11.0.1`) instance of `Semigroup (Either a b)` (excluding `stimes`:
{{{#!hs
-- | @since 4.9.0.0
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:
{{{#!hs
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:
{{{#!hs
instance Monoid a => Monoid (Either a b) where
mempty = Left mempty
}}}
Also `Alternative (Either e)`:
{{{#!hs
instance Monoid e => Alternative (Either e) where
empty = mempty
(<|>) = (<>)
}}}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20180502/30997123/attachment.html>
More information about the Libraries
mailing list