Syntax for union types

Lars Hansen lhansen at
Fri Nov 9 07:31:07 PST 2007

> -----Original Message-----
> From: es4-discuss-bounces at 
> [mailto:es4-discuss-bounces at] On Behalf Of Yuh-Ruey Chen
> Sent: 9. november 2007 01:06
> To: Jason Orendorff
> Cc: es4-discuss at
> Subject: Re: Syntax for union types
> Is there any reason why this proposal isn't being considered?

Yes.  The current syntax has been accepted by the working group.  We
have made use of it in various contexts, (builtins, ESC).  Speaking for
myself I don't see the problem with what we have.

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

Intuition tends to be personal, and the other argument can be turned on
its head (why wouldn't I want to use "int | string" for something else
in the future?).  Since "|" is bitwise or, "||" would have been better,
but that has yet other connotations.

> 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.

This has been discussed at considerable length, and we've concluded that
the current solution represents a workable compromise.

Syntax discussions are not fruitless, but the decisions for the things
you mention above were not arbitrary, and there is, to my knowledge, no
inclination inside the group to revisit the choices.

(More interesting open questions about the language are whether generic
functions ought to be available on instances or discriminating on
structural types, or whether packages ought to be sealable for security,
or whether ES4 precludes the use of current ES3 AOP patterns and how
that might be solved.  Among other things.)


> -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
> >
> >
> >   
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at

More information about the Es4-discuss mailing list