CZ: Multiple Inheritance Without Diamonds

Donna Malayeri


Multiple inheritance has long been plagued with the ``diamond'' inheritance problem, leading to solutions that restrict expressiveness, such as mixins and traits. Instead, we address the diamond problem directly, considering two important difficulties it causes: ensuring a correct semantics for object initializers, and typechecking multiple dispatch in a modular fashion. We show that previous solutions to these problems are either unsatisfactory or cumbersome, and suggest a novel approach: supporting multiple inheritance but forbidding diamond inheritance. Expressiveness is retained through two features: a ``requires'' construct that provides a form of subtyping without inheritance (inspired by Scala), and a dynamically bound ``super'' call similar to that found in traits. Through examples, we illustrate that inheritance diamonds can be eliminated via a combination of ``requires'' and ordinary inheritance. We provide a sound formal model for our language and demonstrate its modularity and expressiveness.

Full paper


Presented at FOOL'09; Saturday, 24 January 2009, Savannah, Georgia, USA.