broken Monad Either instance?

Twan van Laarhoven twanvl at
Fri Dec 2 17:13:47 CET 2011

On 30/11/11 13:55, Christian Maeder wrote:
> Yes, thanks, this works and is worth knowing.
> It looks a bit ugly but is shorter than making a new monad.
> Prelude Control.Monad.Identity Control.Monad.Error>
> runIdentity . runErrorT $ fail "bla" :: Either String ()
> Left "bla"

We should also add a type synonym for Error, like there is for Reader, 
State and RWS:

     type Error e a = ErrorT e a
     error :: Either e a -> Error e a
     error = ErrorT . Indentity
     runError :: Error e a -> Either e a
     runError = runIdentity . runErrorT
     mapError :: Error e a -> Error f a
     mapError f = mapErrorT (Identity . f . runIdentity)

The only problem is that the name 'Error' is taken by a typeclass, and 
'error' by everyone's least favorite prelude function.


More information about the Libraries mailing list