[MLton-user] Wish for a standard sum type
Jesper Louis Andersen
jlouis@mongers.org
Mon, 29 May 2006 16:03:54 +0200
On Sun, 2006-05-28 at 14:41 +0300, Vesa Karvonen wrote:
> The Standard ML Basis Library doesn't contain a general purpose sum type
> like the Either datatype provided by the Haskell prelude:
>
> data Either a b = Left a
> | Right b
>
> I have personally found such a general purpose sum type highly useful, and
> would definitely like to see one in the Basis Library at some point.
>
> The obvious translation to SML would be
>
> datatype ('a, 'b) either = LEFT of 'a
> | RIGHT of 'b
datatype ('a, 'b) either = INL of 'a
| INR of 'b
datatype ('a, 'b) either = LEFT of 'a
| RITE of 'b (Terry Pratchett fans will love)
L | R, A | B is much too general. INL | INR is grateously stolen from a
couple of courses on formal semantics. LEFT | RITE is for fun and play.
I do find it on the scale of THIS | THAT. Of course you define:
inl x = INL x
inr x = INR x
to match it up with the formal semantics more.
j.