Proposal: merge either into transformers

Edward Kmett ekmett at gmail.com
Wed Apr 30 13:31:37 UTC 2014


I personally would rather pay than lose information.


On Wed, Apr 30, 2014 at 6:24 AM, Ross Paterson <R.Paterson at city.ac.uk>wrote:

> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140430/1ae736bd/attachment.html>


More information about the Libraries mailing list