Type parameters

Peter Hall peterjoel at gmail.com
Mon Sep 4 21:23:54 PDT 2006


I have a few questions/comments on this proposal.
(http://developer.mozilla.org/es4/proposals/type_parameters.html)

1. I don't see any discussion about optional Type parameteres (default
values). Wouldn't you sometimes want to be able to something like

   class Factory.<A=Bar> {
        // etc
   }


It is possible to work around this by extending the class with a
non-parametrised type, which provides the parameter. eg:

   class FactoryTemplate.<A> {
        // etc
   }

   class BarFactory extends FactoryTemplate.<Bar> {   }


While this works great, it isn't symmetrical with function arguments.
It would be equivalent to creating additional differently-named
functions in place of using optional arguments.



2. I am also wondering about the implications of not being able to
enforce any constraints on the types that may be used a parameter. But
I'm struggling to find a convincingly realistic example where it would
be useful - so perhaps I will leave that alone...



3. How will static code be exectuted in such classes?

   class Example.<A> {

        {
            // when does code that is placed here run?
            // and, consequently, can it determine A?
        }

        static var a:A;
   }



4. How would reflection implementations be affected by type
parameters? I'm thinking of AS3 here.



Apologies if my questions are naive - I am just an enthusiast in all this :-)
Thanks,


Peter



More information about the Es4-discuss mailing list