import std::io; # A trait's own functions, declared through it outside it, are named through it, # generic as any function is, and std reads numbers by `real::parse::` and # `integer::parse::`. trait shape { def area(&this): f64; } def shape::total(shapes: span): f64 where S: shape { var sum := 0.0; for &each in shapes { sum += each.area(); } return sum; } def shape::unit(): f64 { return 1.0; } trait holder { def held(&this): T; } def holder::pair(x: T): T[2] { return [x, x]; } struct square : shape { var side: f64; } def square::area(&this): f64 { return this.side * this.side; } struct cell : holder { var v: i64; } def cell::held(&this): i64 { return this.v; } def main(): void { val squares: square[2] = [square { side = 2.0 }, square { side = 3.0 }]; println($"{shape::total(squares[:])} {shape::unit()}"); val p := holder::::pair(21); println($"{p[0] + p[1]}"); val c := cell { v = 4 }; println($"{c.held()}"); val f := shape::unit; println($"{f()}"); val r: f32 = real::parse::("1.5").value; val n: u8 = integer::parse::("200").value; println($"{r} {n}"); }