[MLton-user] Wish for a standard sum type
Jesper Louis Andersen
jlouis@mongers.org
Mon, 29 May 2006 20:27:35 +0200
On Mon, 2006-05-29 at 19:54 +0300, Vesa Karvonen wrote:
> Quoting Jesper Louis Andersen <jlouis@mongers.org>:
> > datatype ('a, 'b) either = INL of 'a
> > | INR of 'b
>
> I like this one. Now that I think about it, I recall seeing this
> naming used somewhere (article or book).
>
> The "IN" part also nicely suggests the antonym for the occasionally
> useful partial destructors:
>
> fun outL (INL x) = x
> fun outR (INR x) = x
You are a bit too fast when assuming IN is the opposite of OUT. I
believe (and correct me if I am wrong, please) that IN is a shorthand
for "Inject", so it really means Inject Left, Inject Right.
That said, I like the idea of using out to deconstruct the variants.
I believe we should also steal most of the functions the Data.Either
hierachial haskell library defines. It would make for a nifty package.