I think the iffy feeling comes from the proposal breaking the distributive
law. For example:
Post by Tony Morris
Alternatively :) or more like, something to think about, an Alt instance
class Alt f where
(<!>) :: f a -> f a -> f a
instance Alt Either where
Right b <!> _ = Right b
Left a <!> x = x
There is something iffy about Monoid e => Alternative (Either e) but I
can't put my finger on it.
instance Monoid e => Alternative (Either e) where
empty = Left mempty
Left a <|> Left b = Left (a `mappend` b)
Right a <|> _ = Right a
_ <|> Right b = Right b
instance Monoid e => MonadPlus (Either e) where
This is a reasonably obvious instance which I am pretty sure is law abiding.
It'd be useful for defining a series of computations which may fail, where
we only care about one success.
Libraries mailing list