[Haskell-cafe] Why Either = Left | Right instead of something like Result = Success | Failure

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Fri May 28 19:28:59 EDT 2010


Daniel Fischer <daniel.is.fischer at web.de> writes:

> On Friday 28 May 2010 20:44:20, Donn Cave wrote:
>> Quoth Vo Minh Thu <noteed at gmail.com>,
>> ...
>>
>> > Control.Monad.Error provides an instance for Either.
>>
>> ... in the mtl transformer library, in case anyone else besides
>> myself didn't know that. And I see it has to be there because
>> it depends on the Error typeclass.
>
> Which is considered a wart by some. (Either left) has a perfectly valid 
> Monad instance for any type left (the only slightly difficult thing might 
> be 'fail').

Though how would you set the Left value for some arbitrary type?

>> Though I can't really be sure what the documentation is
>> trying to say.)
>>
>
> In that case, have a look at the code, perhaps that is clearer. (And bug 
> the maintainer(s) to improve the docs.)

IIRC, the basic point is that the Left type has to be one which can be
converted from some arbitrary String value, to take into account the
fail method for that type:

fail :: (Monad m) => String -> m a

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list