Type Parameters are Completely Unnecessary

Brendan Eich brendan at mozilla.org
Tue Mar 4 23:13:46 PST 2008

[Resending my private-in-turn reply, edited a bit. /be]

On Mar 4, 2008, at 10:48 PM, Darryl wrote:

> var numberSet = new TypedSet(Number);

I wanted to point out how we considered making type parameters be  
ordinary call parameters, see:


The latter includes an attempt by Jeff Dyer (look for  — Jeff Dyer  
2006/02/27 14:55) to use a parenthesized parameter list. Then came


There was a belief that we could parameterize Array by type, but in  
ES1-3 it already can be called as a function taking parameters, so  
that hope died. It may have distorted our wish to use a distinct  
bracketed type parameter list, but not much: the problem remains that  
in order to have a strict mode, we need type terms to be constants,  
and in order to keep implementations "small", we do not want any  
fancy analyses to be required.

You can read the rest of the discussion if you have time to kill, but  
the gist of it is that distinct brackets for type parameter lists are  
necessary, the C++, Java, or C# syntax of Vector<double> is hard  
enough to parse that we passed on it, and after struggling to find  
other bracket chars, we ended up using an unambiguous syntactic  
extension: Vector.<double>.

Again, if you believe that all type checking should be written out as  
code, then you don't want type parameters. But you don't want types,  
period, so best to argue that case instead of singling out type  

> which has an add method like
> function(obj){
>     if( obj instanceof Number ){
>         //add it
>     }
> }

That's not type-checking in the optional types sense. It's tedious  
and error-prone, and hard enough that people tend not to write such  
code, instead using duck typing in a more "if it doesn't quack like a  
duck, step on it!" way.

Type parameters follow naturally from wanting types to be first class  
runtime terms, not just values that have to be checked manually.

> As it is, I find
> var numberSet = new Set.<Number>();
> to be incredibly ugly

I guess my plea to put aside syntax and aesthetics didn't work.  
You're being blinded to the meaning, which is where the motivation  

Would you prefer Set<Number> a la C++, Java, and C#?

> I'd go so far as to say that because "types" are
> classes (afaik), there should be absolutely no reason
> you can't refer to types.

Types are not all classes. There are structural types (even today,  
latent in ES3: functions are structural, not nominal). Have you read  
the overview doc at http://ecmascript.org/ yet?


More information about the Es4-discuss mailing list