Last active
August 29, 2015 14:27
-
-
Save JAChapmanII/dd02f08e3a41187ba53b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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