core-lang / core

The Core Programming Language
https://core-lang.dev
MIT License
45 stars 1 forks source link

support generics in traits #68

Open soc opened 1 year ago

soc commented 1 year ago

Consider:

@pub trait Iterator {
  fun next(): Option[Int32]; // this should be made generic
}

Ideally we would have:

@pub trait Iterator[T] {
  fun next(): Option[T];
}

Which compiles, but a trait impls like ...

impl Iterator[Int32] for NoInt32Iterator {
  fun next(): Option[Int32] = None[Int32];
}

... fails compilation with:

return types `Option[Int32]` and `Option[T]` do not match

Feels like we forget specializing the return type.