[Haskell-cafe] Why Either = Left | Right instead of something
like Result = Success | Failure
Alberto G. Corona
agocorona at gmail.com
Thu May 27 13:37:27 EDT 2010
Left-Right also good for representing binary trees.
2010/5/27 C. McCann <cam at uptoisomorphism.net>
> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100527/a595709e/attachment.html
More information about the Haskell-Cafe
mailing list