A foundation for trait-based metaprogramming (extended version)

John Reppy; Aaron Turon. 1 February, 2006.
Communicated by John Reppy.


Scharli et al. introduced traits as reusable units of behavior independent of the inheritance hierarchy. Despite their relative simplicity, traits offer a surprisingly rich calculus. Trait calculi typically include operations for resolving conflicts when composing two traits. In the existing work on traits, these operations (method exclusion and aliasing) are shallow, i.e., they have no effect on the body of the other methods in the trait. In this paper, we present a new trait system, based on the Fisher-Reppy trait calculus, that adds deep operations (method hiding and renaming) to support conflict resolution. The proposed operations are deep in the sense that they preserve any existing connections between the affected method and the other methods of the trait. Our system uses Riecke-Stone dictionaries to support these features. In addition, we define a more fine-grained mechanism for tracking trait types than in previous systems. The resulting calculus is more flexible and expressive, and can serve as the foundation for trait-based metaprogramming, an idiom we introduce. This is an extended version of our workshop paper with the complete formal model and additional details for the soundness proof.

Original Document

The original document is available in PDF (uploaded 1 February, 2006 by John Reppy).