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

C. McCann cam at uptoisomorphism.net
Thu May 27 11:26:38 EDT 2010


On Thu, May 27, 2010 at 10:25 AM, Ionut G. Stan <ionut.g.stan at gmail.com> wrote:
> I was just wondering if there's any particular reason for which the two
> constructors of the Either data type are named Left and Right. I'm thinking
> that something like Success | Failure or Right | Wrong would have been a
> little better.

Because that would confuse matters when using the type for something
other than representing success or failure.

Either is a generic sum type. That is, "Either A B" only means "either
you have an A, or you have a B". Use of Left to represent failure is
merely a matter of convention. Similarly, the generic product type in
Haskell is the 2-tuple--"(A, B)" only means "you have both an A and a
B".

Left and Right work well because they don't carry much extra semantic
baggage, and they make it easy to remember which type parameter goes
with which constructor. Other than the mnemonic value, something even
more bland like This and That would work as well.

Personally, I advocate instead using "Sinister" and "Dexter". Nice and
catchy, don't you think?

- C.


More information about the Haskell-Cafe mailing list