Generics (monomorphized)
Silk generics are compile-time and monomorphized: each applied type like
Vector(int) produces a concrete instantiation at build time (no runtime type
parameters).
Full reference: generics.
Notes#
- supported forms and restrictions: generics
Syntax#
struct Pair(T) {
a: T,
b: T,
}
impl Pair(T) {
public fn first (self: &Pair(T)) -> T { return self.a; }
}
Examples#
Example: generic struct + applied type#
struct Pair(T) {
a: T,
b: T,
}
impl Pair(T) {
public fn first (self: &Pair(T)) -> T { return self.a; }
}
fn main () -> int {
let p: Pair(int) = { a: 1, b: 2 };
return p.first();
}
See also#
Source repository · Edit this page · View Markdown