Type parameters

Peter Hall peterjoel at gmail.com
Tue Sep 5 04:38:19 PDT 2006


> There are a lot of useful cases. Basically when you don't have any
> contraints on the type parameter, all you can do is manipulate it
> abstractly. It works well for all kind of data structures and
> containers, but fails to express reusable components.


This was my feeling too. I am just struggling to concoct a convincing
code example that is not contrived.


> Type parameters are usualy forbidden in static variables, since it does
> not makes sense. Allowing them creates a type hole since you can do
>
> Example.<Int>.a = 3
> var s : String = Example.<String>.a;
>


I wrote my example badly. I was trying to understand how parametrised
types are treated. That is, is each parametrisation a proper type,
having it's static code run once per parametrisation, or is static
code run once when the definition is imported?

e.g.


  class Example.<A> {
       {
            print("hello");
       }
  }

  eStr = new Example.<String>();
  eObj = new Example.<Object>();


Should I expect "hello" to be output once or twice?

Peter



More information about the Es4-discuss mailing list