Gradual typing for first-class classes

Dynamic type-checking and object-oriented programming often go hand-in-hand; scripting languages such as Python, Ruby, and JavaScript all embrace object-oriented (OO) programming. When scripts written in such languages grow and evolve into large programs, the lack of a static type discipline reduces maintainability. A programmer may thus wish to migrate parts of such scripts to a sister language with a static type system. Unfortunately, existing type systems neither support the flexible OO composition mechanisms found in scripting languages nor accommodate sound interoperation with untyped code. In this paper, we present the design of a gradual typing system that supports sound interaction between statically- and dynamically-typed units of class-based code. The type system uses row polymorphism for classes and thus supports mixin-based OO composition. To protect migration of mixins from typed to untyped components, the system employs a novel form of contracts that partially seal classes. The design comes with a theorem that guarantees the soundness of the type system even in the presence of untyped components.

[1]  Cormac Flanagan,et al.  Status report: specifying javascript with ML , 2007, ML '07.

[2]  James H. Morris,et al.  Types are not sets , 1973, POPL.

[3]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.

[4]  Kathryn E. Gray Safe Cross-Language Inheritance , 2008, ECOOP.

[5]  Jan Vitek,et al.  Integrating typed and untyped code in a scripting language , 2010, POPL '10.

[6]  Philip Wadler,et al.  Blame for all , 2011, POPL '11.

[7]  Matthias Felleisen,et al.  Contracts for first-class classes , 2010, DLS '10.

[8]  John C. Mitchell,et al.  Type systems for object-oriented programming languages , 1996 .

[9]  Benjamin C. Pierce,et al.  A bisimulation for dynamic sealing , 2004, Theor. Comput. Sci..

[10]  Audrey Tang Perl 6: reconciling the irreconcilable , 2007, POPL '07.

[11]  Robert Bruce Findler,et al.  Fine-grained interoperability through mirrors and contracts , 2005, OOPSLA '05.

[12]  John Lamping,et al.  Typing the specialization interface , 1993, OOPSLA '93.

[13]  Matthias Felleisen,et al.  Scheme with Classes, Mixins, and Traits , 2006, APLAS.

[14]  Benjamin C. Pierce,et al.  A bisimulation for dynamic sealing , 2007, Theor. Comput. Sci..

[15]  Didier Rémy,et al.  Programming Objects with ML-ART, an Extension to ML with Abstract and Record Types , 1994, TACS.

[16]  Jeffrey S. Foster,et al.  Static type inference for Ruby , 2009, SAC '09.

[17]  Mitchell Wand Type inference for objects with instance variables and inheritance , 1994 .

[18]  Matthias Felleisen,et al.  Semantics Engineering with PLT Redex , 2009 .

[19]  Benjamin C. Pierce,et al.  Theoretical Aspects of Computer Software , 2001, Lecture Notes in Computer Science.

[20]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[21]  Gavin M. Bierman,et al.  Adding Dynamic Types to C# , 2010, ECOOP.

[22]  Luca Cardelli,et al.  Operations on records , 1989, Mathematical Structures in Computer Science.

[23]  Robert Bruce Findler,et al.  Relationally-parametric polymorphic contracts , 2007, DLS '07.

[24]  Sam Tobin-Hochstadt,et al.  Interlanguage migration: from scripts to programs , 2006, OOPSLA '06.

[25]  Sam Tobin-Hochstadt,et al.  Logical types for untyped languages , 2010, ICFP '10.

[26]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.

[27]  Vitaly Shmatikov,et al.  A Core Calculus of Classes and Mixins , 1999, ECOOP.

[28]  Sam Tobin-Hochstadt,et al.  Complete Monitors for Behavioral Contracts , 2012, ESOP.

[29]  Robert Bruce Findler,et al.  Fine-grained interoperability through contracts and mirrors , 2005 .

[30]  Amal Ahmed,et al.  Parametric Polymorphism through Run-Time Sealing or, Theorems for Low, Low Prices! , 2008, ESOP.

[31]  Benjamin C. Pierce,et al.  A record calculus based on symmetric concatenation , 1991, POPL '91.

[32]  Erik Meijer Dynamic typing when needed: The end of the cold war between programming languages , 2004 .

[33]  Mitchell Wand,et al.  Complete Type Inference for Simple Objects , 1987, LICS.

[34]  Gilles Dowek,et al.  Principles of programming languages , 1981, Prentice Hall International Series in Computer Science.

[35]  Matthias Felleisen,et al.  Contracts for higher-order functions , 2002, ICFP '02.

[36]  Robert Bruce Findler,et al.  Operational semantics for multi-language programs , 2007, POPL '07.

[37]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[38]  Kathryn E. Gray Interoperability in a Scripted World: Putting Inheritance & Prototypes Together , 2010 .

[39]  Matthias Felleisen,et al.  Correct blame for contracts: no more scapegoating , 2011, POPL '11.

[40]  Matthias Felleisen,et al.  DrScheme: a programming environment for Scheme , 2002, J. Funct. Program..

[41]  Benedict R. Gaster,et al.  A Polymorphic Type System for Extensible Records and Variants , 1996 .