Syntax for union types

Yuh-Ruey Chen maian330 at
Fri Nov 9 01:06:02 PST 2007

Is there any reason why this proposal isn't being considered?

Not only is (int | string) more intuitive than (int, string), the (int,
string) syntax can be reserved for another yet-unknown purpose.

Along the same lines, I find the syntax for constraining list types to
be unintuitive. [int] is very different from [int, string], and [int,
string] is very different from (int, string). Perhaps that (int, string)
can describe the tuple type. And [int | string] could be syntactic sugar
for [(int | string)]. The usage of "|" improves readability in that
there's no way to confuse a union type with a tuple type.

-Yuh-Ruey Chen

Jason Orendorff wrote:
> On Oct 26, 2007 6:35 PM, James Clark <jjc at> wrote:
> > (int, string) doesn't seem to me to be a syntax that the average JS
> > programmer will guess means union. I would have thought a better choice
> > would be (int | string) (especially given that regexps use |) or a keyword.
> Yep.  I read (int, string) as a tuple type every time.  ML, Haskell,
> Python 3.0... I'm not sure what we gain by going against the grain
> here.
> So it's not a big deal, but switching to (t1 | t2) seems all upside to
> me.  It's a shallow change.  +1.
> -j
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at

More information about the Es4-discuss mailing list