Skip to content

Instantly share code, notes, and snippets.

@JAChapmanII
Last active August 29, 2015 14:27
Show Gist options
  • Save JAChapmanII/dd02f08e3a41187ba53b to your computer and use it in GitHub Desktop.
Save JAChapmanII/dd02f08e3a41187ba53b to your computer and use it in GitHub Desktop.
import std.io;
import std.string;
import core.type;
type string = std.string;
var out = std.io.stdout;
type Cat {
func purr() -> string { return "purrr"; }
func speak() -> string { return "meow"; }
}
type Dog {
func speak() -> string { return "woof"; }
}
type Bird {
func speak() -> string { return "chirp"; }
}
// Animal has speak() -> string only
type Animal = Dog >< Cat;
func pet(Animal animal) -> void {
out.println("petting an %s", core.type.getTypeName(animal));
out.println("result: %s", animal.speak());
}
func main() -> void {
out.print("Hello, World!\n");
Cat cat = new Cat();
pet(cat);
Dog dog = new Dog();
pet(dog);
Bird bird = new Bird();
pet(bird);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment