User loginNavigation |
Implementing abstract classes automatically?Here is an interesting construct I'm working with recently. Say we have an abstract class (trait) with one abstract method do:
trait A {
abstract void do();
}
Now say we have two implementations:
trait B : A {
override void do() { ... }
}
trait C : A {
override void do() { ... }
}
object myUnderspecifiedA : A { ... }
Given an under specified object that extends A, the compiler could choose either B or C to "complete" it; perhaps we have a model that expresses that an object that extends A more often extends B rather than C, so why not just select that? Also, the object might only be able to extend one trait and not the other to implement "do," consider:
trait D : A {
abstract void bar();
}
trait E : D {
override void bar() { ... }
}
trait F : D {
override void bar() { ... }
}
trait B : E {
override void do() { ... }
}
trait G : A {
abstract void foo();
}
trait C : F, G {
override void do() { ... }
}
trait H : G {
override void foo() { ... }
}
object myUnderspecifiedAWithF : A with F { ... }
In this case, the compiler could have the object extend C but not B, since in the latter case the bar method would be implemented in two different ways. Now, the completion of an object with additional traits is recursive: because we have the object extend C, we must now find a trait to implement the abstract foo method from an extended G trait, so we then also choose H (the final solution includes A, F, C, H). Finding a solution for the object then involves finding a trait that implements an abstract method, adding that trait to the extend list, then solving for additional abstract methods; the solution could always dead-end and require backtracking, so this algorithm kind of looks like a Prolog solver. Has anyone heard of a class system like this before? My goal is to have a language where you can under specify a program and the compiler will fill in the gaps by finding traits to implement abstract methods that maintains consistency. A "best" solution could be chosen based on a model that includes "can-be" probabilities. By Sean McDirmid at 2012-05-28 13:53 | LtU Forum | previous forum topic | next forum topic | other blogs | 5683 reads
|
Browse archives
Active forum topics |
Recent comments
2 days 5 min ago
2 days 22 min ago
2 days 23 min ago
3 weeks 2 days ago
4 weeks 1 day ago
4 weeks 1 day ago
4 weeks 2 days ago
4 weeks 2 days ago
4 weeks 2 days ago
4 weeks 5 days ago