A polymorphic record calculus and its compilation

The motivation of this work is to provide a type-theoretical basis for developing a practical polymorphic programming language with labeled records and labeled variants. Our goal is to establish both a polymorphic type discipline and an efficient compilation method for a calculus with those labeled data structures. We define a second-order, polymorphic record calculus as an extension of Girard-Reynolds polymorphic lambda calculus. We then develop an ML-style type inference algorithm for a predicative subset of the second-order record calculus. The soundness of the type system and the completeness of the type inference algorithm are shown. These results extend Milner's type inference algorithm, Damas and Milner's account of ML's let polymorphism, and Harper and Mitchell's analysis on XML. To establish an efficient compilation method for the polymorphic record calculus, we first define an implementation calculus, where records are represented as vectors whose elements are accessed by direct indexing, and variants are represented as values tagged with a natural number indicating the position in the vector of functions in a switch statement. We then develop an algorithm to translate the polymorphic record calculus into the implementation calculus using type information obtained by the type inference algorithm. The correctness of the compilation algorithm is proved ; that is, the compilation algorithm is shown to preserve both typing and the operational behavior of a program. Based on these results, Standard ML has been extended with labeled records, and its compiler has been implemented.

[1]  Didier Rémy,et al.  Typing record concatenation for free , 1992, POPL '92.

[2]  Andrew W. Appel,et al.  Unrolling lists , 1994, LFP '94.

[3]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[4]  Prateek Mishra,et al.  Type Inference with Subtypes , 1990, Theor. Comput. Sci..

[5]  Ryan Stansifer,et al.  Type inference with subtypes , 1988, POPL '88.

[6]  Peter Buneman,et al.  Type inference in a database programming language , 1988, LISP and Functional Programming.

[7]  Atsushi Ohori,et al.  Semantics of Types for Database Objects , 1988, Theor. Comput. Sci..

[8]  Robert Cartwright,et al.  A practical soft type system for scheme , 1997, TOPL.

[9]  Xavier Leroy,et al.  Unboxed objects and polymorphic typing , 1992, POPL '92.

[10]  John C. Mitchell,et al.  Type Systems for Programming Languages , 1991, Handbook of Theoretical Computer Science, Volume B: Formal Models and Sematics.

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

[12]  Ronald Morrison,et al.  An object addressing mechanism for statically typed languages with multiple inheritance , 1989, OOPSLA '89.

[13]  Peter Buneman,et al.  Polymorphism and type inference in database programming , 1996, TODS.

[14]  Didier Rémy,et al.  Type checking records and variants in a natural extension of ML , 1989, POPL '89.

[15]  Jacques Garrigue,et al.  A Label-Selective Lambda-Calculus with Optional Arguments and its Compilation Method , 1995 .

[16]  Wayne Snyder,et al.  Complete Sets of Transformations for General E-Unification , 1989, Theor. Comput. Sci..

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

[18]  Luca Cardelli,et al.  Extensible records in a pure calculus of subtyping , 1994 .

[19]  Matthias Felleisen,et al.  A Syntactic Theory of Sequential Control , 1987, Theor. Comput. Sci..

[20]  Robert Cartwright,et al.  Soft typing , 2004, SIGP.

[21]  John Peterson,et al.  Implementing type classes , 1993, PLDI '93.

[22]  Peter Buneman,et al.  Static type inference for parametric classes , 1989, OOPSLA '89.

[23]  Thierry Coquand,et al.  Inheritance as Implicit Coercion , 1991, Inf. Comput..

[24]  Peter Buneman,et al.  Using Powerdomains to Generalize Relational Databases , 1991, Theor. Comput. Sci..

[25]  Mitchell Wand,et al.  Type inference for record concatenation and multiple inheritance , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[26]  Cordelia V. Hall Using Hindley-Milner type inference to optimise list representation , 1994, LFP '94.

[27]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[28]  John C. Mitchell,et al.  The Semantics of Second-Order Lambda Calculus , 1990, Inf. Comput..

[29]  Robin Milner,et al.  Definition of standard ML , 1990 .

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

[31]  Andrew P. Tolmach Tag-free garbage collection using explicit type parameters , 1994, LFP '94.

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

[33]  Luca Cardelli,et al.  Operations on Records , 1989, Mathematical Foundations of Programming Semantics.

[34]  B. Courcelle Fundamental properties of infinite trees , 1983 .

[35]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[36]  Atsushi Ohori,et al.  A simple semantics for ML polymorphism , 1989, FPCA.

[37]  Luca Cardelli,et al.  A Semantics of Multiple Inheritance , 1984, Information and Computation.

[38]  Thierry Coquand,et al.  Extensional Models for Polymorphism , 1987, Theor. Comput. Sci..

[39]  Atsushi Ohori,et al.  A compilation method for ML-style polymorphic record calculi , 1992, POPL '92.

[40]  J. Girard Une Extension De ĽInterpretation De Gödel a ĽAnalyse, Et Son Application a ĽElimination Des Coupures Dans ĽAnalyse Et La Theorie Des Types , 1971 .

[41]  John C. Mitchell,et al.  On the type structure of standard ML , 1993, TOPL.

[42]  Robert Harper,et al.  Compiling polymorphism using intensional type analysis , 1995, POPL '95.

[43]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[44]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[45]  Henk Barendregt,et al.  The Lambda Calculus: Its Syntax and Semantics , 1985 .

[46]  Bruno Courcelle,et al.  Fundamental Properties of Infinite Trees , 1983, Theor. Comput. Sci..

[47]  Ronald Fagin,et al.  Extendible hashing—a fast access method for dynamic files , 1979, ACM Trans. Database Syst..

[48]  M. Wand,et al.  Corrigendum: complete type interference for simple objects , 1988, [1988] Proceedings. Third Annual Information Symposium on Logic in Computer Science.

[49]  Vasco T. Vasconcelos,et al.  A process-calculus approach to typed concurrent objects , 1995 .

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

[51]  John Mitchell,et al.  Type Inference and Type Containment , 1984, Semantics of Data Types.

[52]  John C. Mitchell,et al.  Type Inference with Extended Pattern Matching and Subtypes , 1993, Fundamenta Informaticae.

[53]  Didier Rémy,et al.  Type inference for records in natural extension of ML , 1994 .

[54]  J. A. Robinson,et al.  A Machine-Oriented Logic Based on the Resolution Principle , 1965, JACM.

[55]  Peter Buneman,et al.  OOPSLA '89 Conference proceedings on Object-oriented programming systems, languages and applications , 1989 .

[56]  Jacques Garrigue,et al.  The typed polymorphic label-selective λ-calculus , 1994, POPL '94.