malayeri.fool07

malayeri.fool07 - Combining Structural Subtyping and...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Combining Structural Subtyping and External Dispatch Donna Malayeri Jonathan Aldrich Carnegie Mellon University { donna+, aldrich+ } @cs.cmu.edu Abstract Nominal subtyping (or user-defined subtyping) and structural sub- typing each have their own strengths and weaknesses. Nominal subtyping allows programmers to explicitly express design intent, and, when types are associated with run time tags, enables run- time type tests (e.g., downcasts) and external/multimethod dis- patch. On the other hand, structural subtyping is flexible and com- positional, allowing unanticipated reuse. To date, nearly all object- oriented languages fully support only one subtyping paradigm or the other. In this paper, we describe a core calculus for a language that combines the key aspects of nominal and structural subtyping in a unified framework. Our goal is to combine the flexibility of struc- tural subtyping while still allowing static typechecking of external methods. 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 de- sign of future languages that enjoy the benefits of both nominal and structural subtyping. 1. Introduction In the research community, structural subtyping is considered a clean and theoretically pleasing account of subtyping. However, the most widely used object-oriented languages provide little or no support for structural subtyping, relying instead on user-defined nominal subtyping. Each kind of subtyping has its merits, but no existing language combines the two in a uniform way. Nominal subtyping allows the programmer to express and en- force design intent explicitly. A programmers defined subtyping hierarchy serves as checked documentation that specifies how the various parts of a program are intended to work together. Ex- plicit specification also has the advantage of preventing acci- dental subtyping relationships, such as the standard example of cowboy.draw() and circle.draw() . Nominal subtyping also al- lows recursive types to be easily and transparently defined, since re- cursion can simply go through the declared names. Another advan- tage is that error messages are usually much more comprehensible, since (for the most part) every type in a type error is one that the programmer has defined explicitly. Finally, and most importantly, nominal subtyping is necessary for run-time subtyping tests (such as downcasts) as well as external and multimethod dispatch. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee....
View Full Document

Page1 / 11

malayeri.fool07 - Combining Structural Subtyping and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online