Nature of Parametrized types

Peter Hall peter.hall at memorphic.com
Sat Mar 15 07:32:21 PDT 2008


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.

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.


2. Is it legal to extend a general parametrized class, or may you only
extend a specific parametrization?
ie, is this allowed:
class T.<A> { var x:A; }
class S.<A> extends T { }
?
This seems to have all kinds of problems. For one, there is no
equivalent of "super()" to pass the parameters to the super class.
However, certain uses of parametrized classes might be unfeasible if
you can't extend the class without choosing a parametrization.


3. It seems that there are use-cases for statics being
per-parametrization and also for them being global for all
parametrizations. If I wanted to keep a count of all the instances of
a parametrized class had been created, I'd need a static var to be
global across all parametrizations. But there are probably more use
cases for it to be per-parametrization. So it would actually be really
nice if you could choose between these different scopes. Without
introducing new keywords, using a double "static static" could
indicate that a property is static across all parametrizations, while
a single  "static" would indicate that a property was static on a
per-parametrization basis.
e.g:

class A.<K> {
  public static static var a:int = 0;
  public static var b:int = 0;
}

A.<int>.a ++;
A.<int>.b ++;

A.<string>.a; // 1
A.<string>.b; // 0

I suppose an alternative would be a magic always-open namespace.


Peter



More information about the Es4-discuss mailing list