Right now generics are extremely primitive in their feature set. I'd like to enhance them to allow to be typed, which would enable two key features:
- Allowing constant values, which would be useful for declaring constants and array sizes
- Allowing trait types, which would constrain the generic types allowed.
Example syntax:
public struct StaticArray<SIZE:u32, T> {
elements: [SIZE]T
}
...
var buffer = StaticArray<16, f32>{}
buffer[0] = 4f
For trait argument types:
trait Hashable<T> {
hash: func<T>(T>): u32;
}
trait Comparable<T> {
equals: func<T>(T,T): i32;
}
// Now we know any supplied K must have a method "hash" and V must have a method "equals"
public struct HashMap<K: Hashable<K>, V: Comparable<V>> {
...
}
Right now generics are extremely primitive in their feature set. I'd like to enhance them to allow to be typed, which would enable two key features:
Example syntax:
For trait argument types: