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

Donn Cave donn at avvanta.com
Fri May 28 12:04:48 EDT 2010


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.

I think though that you can't have it both ways - Either
Left
  "Either is universally understood to be for success/failure-with-error"
or Right
  "Either does not imply any meaning, it represents any A/B option pair"

We're really stuck with the latter - that's why, as explained
early in this thread, the names are essentially value free
(it's Left/Right, not Wrong/Right.)  Since Either doesn't imply
meaning, its use with errors presents an ambiguity that has to
be resolved by the reader - something I have to comprehend if
I read your code, and it might indeed be easier to read code
that uses a type that, though unique to the code, has names that
reflect its meaning.

	Donn Cave, donn at avvanta.com



More information about the Haskell-Cafe mailing list