[MLton-user] Wish for a standard sum type

Andreas Rossberg AndreasRossberg@web.de
Mon, 29 May 2006 17:54:41 +0200


"Vesa Karvonen" <vesa.karvonen@cs.helsinki.fi>:
>
> 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?

For the Alice library we chose

  datatype ('a,'b) alt = FST of 'a | SND of 'b

although I'm not particularly excited about it. It has the advantage that it
is less likely to collide with user datatype constructors.  (However, I
always disliked "either" as a type name, and it reads even worse in postfix
notation ;-) )

I'm not too fond of THIS/THAT, because they do not look properly symmetric
to me.

Regarding casing, I believe that uppercase constructors are actually
prescribed by the Basis Spec: it suggests the "signature convention" for
ordinary constructors, and the "structure convention" for exception
constructors. Can't say I ever liked that either, though...

  - Andreas