shared abstract class Enumeration(integer) of one | two | three
satisfies Comparable<Enumeration> & Ordinal<Enumeration> {
shared Integer integer;
shared actual Comparison compare(Enumeration other) {
return this.integer <=> other.integer;
}
shared actual Integer distanceFrom(Enumeration other) {
return this.integer.distanceFrom(other.integer);
}
}
shared object one extends Enumeration(1) {
shared actual String string = "one";
shared actual Enumeration predecessor = bottom;
shared actual Enumeration successor { return two; }
}
shared object two extends Enumeration(2) {
shared actual String string = "two";
shared actual Enumeration predecessor { return one; }
shared actual Enumeration successor { return three; }
}
shared object three extends Enumeration(3) {
shared actual String string = "three";
shared actual Enumeration predecessor { return two; }
shared actual Enumeration successor = bottom;
}
void run() {
for( Enumeration e in one .. three){
print( e );
}
}