[Haskell-cafe] Either as a Monad instance

Ross Paterson ross at soi.city.ac.uk
Tue Oct 3 03:49:34 EDT 2006


On Tue, Oct 03, 2006 at 10:44:49AM +1000, Thomas Conway wrote:
> I've been [trying to] grapple with the various monads and
> transformers, and it occurs to me that the standard instance for
> Either as a monadic type is unnecessarily restrictive. Is there a
> compelling reason that it is not just
> 
> instance Monad (Either e) where
>    return = Right
>    (Left e) >>= f = Left e
>    (Right x) >>= f = f x
> 
> abort = Left

That is the definition one would expect, but the restriction was added
so that the instance could include a definition of fail.  It's evidence
that including fail in Monad is a wart, IMO.  Using strings to represent
errors has severe limitations.



More information about the Haskell-Cafe mailing list