[Haskell-cafe] Either as a Monad instance

Lennart Augustsson lennart at augustsson.net
Tue Oct 3 07:52:54 EDT 2006


On Oct 3, 2006, at 03:49 , Ross Paterson wrote:

> 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.

Yes, having fail in the Monad is a horrible wart.
And like some other warts in Haskell it was added to cure the symptom  
rather than the disease. :(

	-- Lennart



More information about the Haskell-Cafe mailing list