Skip to content

Instantly share code, notes, and snippets.

@Spartee
Created August 2, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spartee/8fe48f54a32f44f1bceb95a59175a188 to your computer and use it in GitHub Desktop.
Save Spartee/8fe48f54a32f44f1bceb95a59175a188 to your computer and use it in GitHub Desktop.
module SomeAnimals {
class Animal {
var animalType: string;
}
class Bird: Animal {
proc init(aType: string) {
this.animalType = aType;
}
proc fly() {
writeln("flying..");
}
}
class Fish: Animal {
proc init(aType: string) {
this.animalType = aType;
}
proc swim() {
writeln("swimming..");
}
}
} // module SomeAnimals
proc main() {
use SomeAnimals;
const fish: Animal = new Fish("fishtype");
const bird: Animal = new Bird("birdtype");
const animals = [fish, bird];
for animal in animals {
select animal.animalType {
when "fishtype" do (animal:Fish).swim();
when "birdtype" do (animal:Bird).fly();
}
}
} // proc main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment