Eliminating distinctions of class: Using prototypes to model virtual classes

DL Hutchins - Proceedings of the 21st annual ACM SIGPLAN …, 2006 - dl.acm.org
Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented …, 2006dl.acm.org
In mainstream OO languages, inheritance can be used to add new methods, or to override
existing methods. Virtual classes and feature oriented programming are techniques which
extend the mechanism of inheritance so that it is possible to refine nested classes as well.
These techniques are attractive for programming in the large, because inheritance becomes
a tool for manipulating whole class hierarchies rather than individual classes. Nevertheless,
it has proved difficult to design static type systems for virtual classes, because virtual classes …
In mainstream OO languages, inheritance can be used to add new methods, or to override existing methods. Virtual classes and feature oriented programming are techniques which extend the mechanism of inheritance so that it is possible to refine nested classes as well. These techniques are attractive for programming in the large, because inheritance becomes a tool for manipulating whole class hierarchies rather than individual classes. Nevertheless, it has proved difficult to design static type systems for virtual classes, because virtual classes introduce dependent types. The compile-time type of an expression may depend on the run-time values of objects in that expression.We present a formal object calculus which implements virtual classes in a type-safe manner. Our type system uses a novel technique based on prototypes, which blur the distinction between compile-time and run-time. At run-time, prototypes act as objects, and they can be used in ordinary computations. At compile-time, they act as types. Prototypes are similar in power to dependent types, and subtyping is shown to be a form of partial evaluation. We prove that prototypes are type-safe but undecidable, and briefly outline a decidable semi-algorithm for dealing with them.
ACM Digital Library