Nature of Parametrized types

Graydon Hoare graydon at
Mon Mar 17 11:05:48 PDT 2008

Peter Hall wrote:
> I have a few questions/comments about parametrized types. Some I know
> has been discussed, but I still unclear on the outcome of those
> conversations.

Good questions!

> 1. If there is a type T.<J,K>, can T be referenced itself, or must it
> be referenced for some specific values of J and K?
> That is, can I say:
> T1 = T;
> or must it always be:
> T1 = T.<A, B>;
> My understanding is that, conceptually, T is not a type by itself but
> that a type is generated each time that a different combination of
> parameters is supplied. Is this understanding correct? If so, it
> pretty much enforces that static properties are not shared between
> each parametrization.

This question is also raised in tickets #247 and #249, as well as some 
recent committee discussion. The conclusion I think we've reached is to 
immitate C++ and C#, not Java. Or as Lars summarized, given this class:

 >   class Cls.<T> {
 >       static var v;
 >   }

we are going to spec the following:

 >   - Cls.v is nonsensical
 >   - You have to write Cls.<int>.v
 >   - Cls.<int>.v is different from Cls.<bool>.v
 >   - The result of
 >       var p = Cls.<T>
 >       var q = Cls.<T>
 >       p === q
 >     is always true.

In other words, there is no sharing between instantiations on non-equal 
type arguments, but all instantiations on equal type arguments should 
produce the same (memoized) instantiated type / class, with sharable 
static slots on the classes.

At present, I believe the RI is in violation of these rules. But it is 
the intended position.

Note that this is not to say that the type "Cls" is nonsensical on its 
own. Some operations are possible with it: it can be compared to other 
types, it can be captured as a value and passed around, and it can be 
instantiated with argument types. You just can't "reach into" it before 
it's been parameterized, any more than you can "reach into" an 
un-applied function.

> 2. Is it legal to extend a general parametrized class, or may you only
> extend a specific parametrization?

Only a specific parameterization.

> 3. It seems that there are use-cases for statics being
> per-parametrization and also for them being global for all
> parametrizations. 

There are certainly some plausible use cases, but they are (I think) 
beyond the scope of what we're doing this time around. As are quite a 
number of extensions to parametric types we've seen in the wild. If they 
become pressing in the future, future editions may address them.


More information about the Es4-discuss mailing list