[MLton-user] Wish for a standard sum type
Vesa Karvonen
vesa.karvonen@cs.helsinki.fi
Sun, 28 May 2006 14:41:42 +0300
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
but I find it decidedly inconvenient that the constructor names are of
different length. Perhaps the following would be a good alternative:
datatype ('a, 'b) either = THIS of 'a
| THAT of 'b
What do you think? Can you think of better constructor names for either?
-Vesa Karvonen