import std::io; trait Into { def into(&this): T; def twice(&this): T[2] { return [this.into(), this.into()]; } } trait Map { def get(&this, key: K): V; } struct counted { var it: &Into; } struct meters: Into> { var v: f64; } def meters::into(&this): span { return this.v < 3.0 ? "2m" : "far"; } struct count { var n: int; } def count::into(&this): int { return this.n * 10; } struct box { var value: T; } def box::into(&this): T { return this.value; } struct table { var keys: span>; var values: span; } def table::get(&this, key: span): int { for i in 0..this.keys.length { if this.keys[i] == key { return this.values[i]; } } return -1; } def show(x: &Into>): span { return x.into(); } def total(xs: span): int { var t := 0; for x in xs { t += x.it.into(); } return t; } def pick(x: &Into): T { return x.into(); } def convert(x: &T): U where T: Into { return x.into(); } def lookup(m: &Map, key: K): V { return m.get(key); } def main(): void { val m := meters{ 2 }; println($"{show(m)} {m.twice()} {convert::>(m)}"); val c := count{ 3 }; val b := box{ 4 }; val more := box{ 5 }; var parts: counted[3] = [counted{ &c }, counted{ &b }, counted{ &more }]; val held := span::::over((&parts) as *counted, 3); val word := box::>{ "s" }; println($"{total(held)} {pick(c)} {pick(word)} {parts[1].it.twice()} {parts[0].it.twice()}"); val keys: span[2] = ["a", "b"]; val values: int[2] = [1, 2]; val t := table{ span::>::over((&keys) as *span, 2), span::::over((&values) as *int, 2) }; val key := "b"; println($"{lookup(t, key)} {(&t as &Map, int>).get(key)}"); }