Paste: multiple dispatch
Author: | kssreeram |
Mode: | text |
Date: | Wed, 4 Aug 2010 04:01:39 |
Plain Text |
record Human {
}
record Dog {
}
variant Animal = Human | Dog;
procedure what;
overload what(x:Human) = "Human";
overload what(x:Dog) = "Dog";
procedure printPair;
overload printPair(a:Human, b:Human) { println(what(a), ", ", what(b)); }
overload printPair(a:Human, b:Dog) { println(what(a), ", ", what(b)); }
overload printPair(a:Dog, b:Human) { println(what(a), ", ", what(b)); }
overload printPair(a:Dog, b:Dog) { println(what(a), ", ", what(b)); }
main() {
var v = Vector[Animal]();
push(v, Animal(Human()));
push(v, Animal(Dog()));
for (a in v)
for (b in v)
printPair(*a, *b);
}
New Annotation