[Haskell-cafe] ErrorT instance of MonadPlus

Dmitry Olshansky olshanskydr at gmail.com
Fri Feb 26 13:01:20 EST 2010


ErrorT instance of MonadPlus define that in case of fail both arguments of
mplus a value of Error will be the Error of second computation:

    m `mplus` n = ErrorT $ do        a <- runErrorT m        case a of
           Left  _ -> runErrorT n            Right r -> return (Right

Could it be changed in this way:

    m `mplus` n = ErrorT $ do        a <- runErrorT m        case a of
           Left  e -> do

                  b <- runErrorT n

                  case b of

                      Left e' -> return $ Left (e `eplus` e')

                      r -> return r

            r -> return r

where `eplus` could be placed in class Error a:

eplus :: a -> a -> a

eplus x y = y -- default implementation

In this case we could combine Errors more flexible.

Best regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100226/0be63bc5/attachment.html

More information about the Haskell-Cafe mailing list