21 lines
655 B
Plaintext
21 lines
655 B
Plaintext
import std::io;
|
|
trait into<T> { def into(&this): T; }
|
|
trait pair<T>: into<T> {
|
|
def twice(&this): T { return this.into(); }
|
|
}
|
|
trait shown { def show(&this): string; }
|
|
trait both { def first(&this): i64; def show(&this): string; }
|
|
struct one: pair<i64> { var v: i64; }
|
|
def one::into(&this): i64 { return this.v; }
|
|
struct card { var n: i64; }
|
|
def card::show(&this): string { return "card"; }
|
|
def card::first(&this): i64 { return this.n; }
|
|
def tell(x: &shown): string { return x.show(); }
|
|
def main(): void {
|
|
val o := one{ v = 5 };
|
|
val p: &pair<i64> = &o;
|
|
val c := card{ n = 2 };
|
|
val b: &both = &c;
|
|
println($"{p.twice()} {tell(b)} {b.first()}");
|
|
}
|