Skip to content

Instantly share code, notes, and snippets.

@schtibe
Created June 14, 2011 18:27
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 schtibe/1025518 to your computer and use it in GitHub Desktop.
Save schtibe/1025518 to your computer and use it in GitHub Desktop.
MyTypeing in OOPLSS
class A {
def __construct(x: Int) {
self.x = x;
}
def m(): MyType {
return self;
}
def n(): MyType {
return self;
}
var x: Int;
var y: MyType;
}
class B {
def __construct(s: String) {
self.s = s;
}
def o(): MyType {
return self;
}
var s: String;
var k: MyType;
}
class C subtypeOf A subclassOf B {
def __construct(): A(5), B("Foo") {
}
def p(): Void {
k = k.k; // OK
k = self.k; // OK
//k = m(); // Fail
//k = B.k; // Fail
//k = s; // OK -- Diese Richtung darf nicht gehen
//s = k; // Fail -- Diese schon
//y = y; // Fail
y = y.y; // OK
//y = A.y; // Fail
//x = A.m().m().x; // Fail
//x = A.m().x; // Fail
x = A.x; // OK
x = 3; // OK
//B.s = B.o().s; // Fail
B.s = B.s; // OK
B.s = "foo"; // OK
}
def m(): MyType {
return self;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment