import std::io; # A constant a trait gives a value is a default, which a type naming the trait # and giving none of its own takes, worked out for that type, with `self` the # type and the trait's parameters its arguments, as a default method is. A type # giving its own keeps it, and one satisfying the trait only by its shape gives # each constant itself. trait sized { const n: u64 = size_of::() + size_of::(); } trait named { const name := "unnamed"; const count: u64 = 2; } struct wide : sized, named { var a: u64; } struct thin : sized, named { var a: u8; } const thin::name := "thin"; struct shaped { var b: u8; } const shaped::name := "shaped"; const shaped::count: u64 = 3; def total(): u64 where T: sized { return T::n; } def name_of(): strview where T: named { return T::name; } def buffer(): u64 where T: named { var held: u8[T::count]; return held.length; } def main(): void { println($"{total::()} {total::()} {wide::n} {thin::n}"); println($"{name_of::()} {name_of::()} {name_of::()} {wide::name}"); println($"{buffer::()} {buffer::()}"); }