[Grace-core] Class syntax and type parameters

Timothy Jones tim at ecs.vuw.ac.nz
Tue Nov 11 17:45:21 PST 2014


On 11/11, Andrew P. Black wrote:
> factory method list<T> {
>     inherits collectionFactory.trait<T>
> 
>     method withAll(a:Collection<T>) -> List<T> {
>         object {
>             inherits indexable.trait<T>
>             var inner := _prelude.PrimitiveArray.new(a.size * 2 + 1)
>             var size is public := 0
>             for (a) do {x->
>                 inner.at(size)put(x)
>                 size := size + 1
>             }

Apparently James also asked this question, but didn't send it to the list:
what's in the collectionFactory.trait that requires the generic parameter at
that point? The current (untyped) implementation of that class is this:

  class collectionFactory.trait {
      // requires withAll(elts : Collection<T>) -> Collection<T>
      method with(*a) { self.withAll(a) }
      method empty { self.with() }
  }

Are you proposing to add the generic parameter to the trait? Why can it not just
be on the methods? (with<T>(*a : T), empty<T>)

-- 
Tim


More information about the Grace-core mailing list