
I personally would rather pay than lose information.
On Wed, Apr 30, 2014 at 6:24 AM, Ross Paterson
On Wed, Apr 30, 2014 at 06:00:50PM +0900, Kei Hibino wrote:
I discovered mplus of ExceptT doesn't call mappend to accumulate error states which is different from origitnal EitherT like below. I suppose this EitherT semantics is more useful than fixed adoption of last error state. (For example, Last Monoid is pre-defined in base)
ExceptT
instance (Monad m, Monoid e) => MonadPlus (ExceptT e m) where mzero = ExceptT $ return (Left mempty) ExceptT m `mplus` ExceptT n = ExceptT $ do a <- m case a of Left _ -> n -- throw left error away Right x -> return (Right x)
EitherT
instance (Monad m, Monoid e) => Alternative (EitherT e m) where EitherT m <|> EitherT n = EitherT $ m >>= \a -> case a of Left l -> liftM (\b -> case b of Left l' -> Left (mappend l l') -- mappend error states Right r -> Right r) n Right r -> return (Right r)
empty = EitherT $ return (Left mempty)
Yes, the ExceptT instance is similar to the ErrorT one. The accumulating one in EitherT is more flexible (and consistent with using mempty in the mzero case), but it's also more expensive than the tail call in the ErrorT version.
What do others think? _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries