{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ecoop08 - Integrating Nominal and Structural Subtyping...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Integrating Nominal and Structural Subtyping Donna Malayeri and Jonathan Aldrich Carnegie Mellon University, Pittsburgh, PA 15213, USA, { donna, aldrich } @cs.cmu.edu Abstract. Nominal and structural subtyping each have their own strengths and weaknesses. Nominal subtyping allows programmers to explicitly express de- sign intent, and, when types are associated with run time tags, enables run-time type tests and external method dispatch. On the other hand, structural subtyping is flexible and compositional, allowing unanticipated reuse. To date, nearly all object-oriented languages fully support one subtyping paradigm or the other. In this paper, we describe a core calculus for a language that integrates the key aspects of nominal and structural subtyping in a unified framework. We have also merged the flexibility of structural subtyping with statically typechecked exter- nal methods, a novel combination. We prove type safety for this language and illustrate its practical utility through examples that are not easily expressed in other languages. Our work provides a clean foundation for the design of future languages that enjoy the benefits of both nominal and structural subtyping. 1 Introduction In a language with structural subtyping, a type U is a subtype of T if its methods and fields are a superset of T ’s methods and fields. The interface of a class is simply its public fields and methods; there is no need to declare a separate interface type. In a language with nominal subtyping, on the other hand, U is a subtype of T if and only if it is declared to be. Accordingly, structural subtyping can be considered intrinsic , while nominal subtyping is declarative . Each kind of subtyping has its merits, but a formal model has not been developed for a language that integrates the two subtyping disciplines. Structural subtyping offers a number of advantages. It is often more expressive than nominal subtyping, as subtyping relationships do not need to be declared ahead of time. It is compositional and intrinsic, existing outside of the mind of the programmer. This has the advantage of supporting unanticipated reuse—programmers don’t have to plan for all possible scenarios. Additionally, structural subtyping is often more notationally succinct. Programmers can concisely express type requirements without having to de- fine an entire subtyping hierarchy. In nominal systems, some situations may require multiple inheritance or an unnecessary proliferation of types; in a structural system, the desired subtyping properties just arise naturally from the base cases. Finally, structural subtyping is far superior in contexts where the structure of the data is of primary im- portance, such as in data persistent environments or distributed computing. In contrast, nominal subtyping can lead to unnecessary versioning problems: if some class C is
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
modified to C 0 (perhaps to add a method m), C 0 objects cannot be serialized and sent to a distributed process with the original definition C , even if C 0 is a strict extension of C .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}