Files
boring-lang/examples/generics.bl

28 lines
394 B
Plaintext
Raw Normal View History

2022-03-12 04:35:48 -07:00
type MyTrait trait {}
type Pair[K, V: MyTrait] struct {
k: K,
v: V,
}
type Value struct {
value: i64,
}
impl MyTrait for Value {}
impl [K, V: MyTrait] Pair[K, V] {
fn get_value[T](self: Self, a: T): V {
return self.v;
}
}
fn main(): i64 {
2022-10-10 17:13:17 -06:00
let a = Pair[i64, Value]{
2022-03-12 04:35:48 -07:00
k: 4,
v: Value{value: 6},
};
2022-10-10 17:13:17 -06:00
return a.get_value[i64](999).value;
2022-03-12 04:35:48 -07:00
}