A first-class approach to genericity

This paper describes how to add first-class generic types---including mixins---to strongly-typed OO languages with nominal subtyping such as Java and C#. A generic type system is "first-class" if generic types can appear in any context where conventional types can appear. In this context, a mixin is simply a generic class that extends one of its type parameters, e.g., a class C that extends T. Although mixins of this form are widely used in Cpp (via templates), they are clumsy and error-prone because Cpp treats mixins as macros, forcing each mixin instantiation to be separately compiled and type-checked. The abstraction embodied in a mixin is never separately analyzed.Our formulation of mixins using first-class genericity accommodates sound local (class-by-class) type checking. A mixin can be fully type-checked given symbol tables for each of the classes that it directly references---the same context in which Java performs incremental class compilation. To our knowledge, no previous formal analysis of first-class genericity in languages with nominal type systems has been conducted, which is surprising because nominal subtyping has become predominant in mainstream object-oriented programming languages.What makes our treatment of first-class genericity particularly interesting and important is the fact that it can be added to the existing Java language without any change to the underlying Java Virtual Machine. Moreover, the extension is backward compatible with legacy Java source and class files. Although our discussion of a practical implementation strategy focuses on Java, the same implementation techniques could be applied to other object-oriented languages such as C# or Eiffel that support incremental compilation, dynamic class loading, and nominal subtyping.

[1]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[2]  Andrew C. Myers,et al.  Parameterized types for Java , 1997, POPL '97.

[3]  Giorgio Ghelli Recursive Types Are not Conservative over F , 1993, TLCA.

[4]  Mirko Viroli,et al.  On Variance-Based Subtyping for Parametric Types , 2002, ECOOP.

[5]  Robert Cartwright,et al.  The case for run-time types in generic Java , 2002, PPPJ/IRE.

[6]  David A. Moon Object-oriented programming with flavors , 1986, OOPSLA 1986.

[7]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[8]  William R. Cook,et al.  Mixin-based inheritance , 1990, OOPSLA/ECOOP '90.

[9]  Guy L. Steele,et al.  Growing a Language , 1999, High. Order Symb. Comput..

[10]  Davide Ancona,et al.  A theory of mixin modules: basic and derived operators , 1998, Mathematical Structures in Computer Science.

[11]  Martin Odersky,et al.  Making the future safe for the past: adding genericity to the Java programming language , 1998, OOPSLA '98.

[12]  Robert Cartwright,et al.  Compatible genericity with run-time types for the Java programming language , 1998, OOPSLA '98.

[13]  Luca Cardelli,et al.  A Semantics of Multiple Inheritance , 1984, Inf. Comput..

[14]  Giorgio Ghelli,et al.  Coherence of Subsumption, Minimum Typing and Type-Checking in F<= , 1992, Math. Struct. Comput. Sci..

[15]  Robert Cartwright,et al.  Efficient Implementation of Run-time Generic Types for Java , 2002, Generic Programming.

[16]  Luca Cardelli,et al.  On understanding types, data abstraction, and polymorphism , 1985, CSUR.

[17]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[18]  Philip Wadler,et al.  Featherweight Java: a minimal core calculus for Java and GJ , 2001, TOPL.

[19]  Luca Cardelli,et al.  An Extension of System F with Subtyping , 1994, Inf. Comput..

[20]  Andrew Kennedy,et al.  Design and implementation of generics for the .NET Common language runtime , 2001, PLDI '01.

[21]  William R. Cook,et al.  A denotational semantics of inheritance , 1989 .

[22]  John H. Reppy,et al.  Extending Moby with Inheritance-Based Subtyping , 2000, ECOOP.

[23]  Paolo Baldan,et al.  Basic Theory of F-Bounded Quantification , 1999, Inf. Comput..

[24]  Davide Ancona,et al.  Jam - A Smooth Extension of Java with Mixins , 2000, ECOOP.

[25]  Benjamin C. Pierce,et al.  Bounded Quantification is Undecidable , 1994, Inf. Comput..

[26]  Atsushi Igarashi,et al.  On Inner Classes , 2000, ECOOP.

[27]  Matthias Felleisen,et al.  Classes and mixins , 1998, POPL '98.

[28]  Martin Odersky,et al.  Pizza into Java: translating theory into practice , 1997, POPL '97.

[29]  Alan Snyder,et al.  CommonObjects: an overview , 1986, OOPWORK '86.

[30]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[31]  J. B. Wells,et al.  Typability and type checking in the second-order /spl lambda/-calculus are equivalent and undecidable , 1994, Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science.

[32]  Davide Ancona,et al.  A Theory of Mixin Modules: Algebraic Laws and Reduction Semantics , 2002, Math. Struct. Comput. Sci..

[33]  Gilad Bracha,et al.  The programming language jigsaw: mixins, modularity and multiple inheritance , 1992 .

[34]  William Cook,et al.  A Proposal for Making Eiel Type-safe , 1989 .

[35]  Kim B. Bruce,et al.  PolyTOIL: A Type-Safe Polymorphic Object-Oriented Language , 1995, ECOOP.

[36]  Matthias Felleisen,et al.  A Programmer's Reduction Semantics for Classes and Mixins , 1999, Formal Syntax and Semantics of Java.

[37]  Guy L. Steele,et al.  Growing a Language , 1999, High. Order Symb. Comput..

[38]  Kim B. Bruce,et al.  A Modest Model of Records, Inheritance and Bounded Quantification , 1990, Inf. Comput..

[39]  Ole Agesen,et al.  Mixed-mode Bytecode Execution , 2000 .

[40]  Stephen N. Freund,et al.  Adding type parameterization to the Java language , 1997, OOPSLA '97.

[41]  John H. Reppy,et al.  Inheritance-Based Subtyping , 2002, Inf. Comput..

[42]  Mirko Viroli,et al.  Parametric polymorphism in Java: an approach to translation based on reflective features , 2000, OOPSLA '00.

[43]  Matthew Flatt,et al.  Jiazzi: new-age components for old-fasioned Java , 2001, OOPSLA '01.