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

Vo Minh Thu noteed at gmail.com
Fri May 28 13:21:20 EDT 2010


2010/5/28 Donn Cave <donn at avvanta.com>:
> Quoth Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>,
>
>>   Whilst the Either type isn't officially used for
>> errors, that is how it is usually treated in Haskell with the consensus
>> that Left = failure and Right = success (note that due to how its
>> defined it also has to be this way for Either's Monad instance to
>> work).
>
> I'm glad you mentioned that, I was going to mention how natural it
> would seem for Either to be an instance of Monad, given that it is
> used as you say by consensus for errors ... but something seems to
> be wrong with my libraries:
>
>    No instance for (Monad (Either [Char]))
>      arising from a use of `return' at except.hs:25:24-29
>    Possible fix:
>      add an instance declaration for (Monad (Either [Char]))
>
> So, I understand how to make a Monad instance, and I guess your
> point stands (as demonstrated by the expected type of (Either String)),
> but it's funny that Either is understood to have a Monad instance
> even though that's only implied, and not supplied.
>
> [snip]

Hi,

Control.Monad.Error provides an instance for Either.

Cheers,
Thu


More information about the Haskell-Cafe mailing list