Type inference with simple subtypes

ion clause, we use A -{x: σ} to denote the set difference, i.e., the type assignment defined by removing x: σ from A. G(x) = { s⊆t }, { x:s} ⊃ x:t G(MN) = let C1, A1 ⊃ M:σ = G(M) C2, A2 ⊃ N:τ = G(N), with type variables renamed to be disjoint from those in G(M) S = UNIFY({ α=β | x:α∈A1 and x:β∈A2} ∪ { σ=τ→t}) where t is a fresh type variable in SC1∪SC2∪{St⊆u}, SA1∪SA2 ⊃ MN:u where u is a fresh type variable G(λx.M) = let C, A ⊃ M:τ = G(M) in if x:σ∈A for someσ then C∪{ σ→τ⊆u}, (A -{x: σ}) ⊃ λx.M:u else C∪{s→τ⊆u}, A ⊃ λx.M:u, where s, u are fresh type variables The algorithm could concei vably fail in the application case if the call to UNIFY fails. Howev er, we will see that this does not happen. It is not to hard to pro ve that if G(M) succeeds, then it produces a pro vable typing for M. THEOREM 13. If G(M) = C,A ⊃ M:σ, then− C,A⊃ M:σ. It follows, by Lemma 11, that e v ry instance of G(M) is a pro vable typing for M. Conversely, every provable typing for M is an instance of G(M). THEOREM 14. Suppose− C,A ⊃ M:σ. Then G(M) succeeds and produces a typing with C,A⊃ M:σ as an instance. Both theorems are pro ved below. From Lemma 2, we kno w that every term has a pro vable CC typing. Therefore, Theorem 14 implies G(M) al ways succeeds.

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

[2]  Mitchell Wand,et al.  On the complexity of type inference with coercion , 1989, FPCA.

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

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

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

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

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

[8]  John C. Mitchell,et al.  Coercion and type inference , 1984, POPL.

[9]  Dana S. Scott,et al.  Data Types as Lattices , 1976, SIAM J. Comput..

[10]  John C. Mitchell,et al.  ML with extended pattern matching and subtypes , 1988, LISP and Functional Programming.

[11]  Albert R. Meyer,et al.  What is a Model of the Lambda Calculus? , 1982, Inf. Control..

[12]  Gordon D. Plotkin,et al.  An ideal model for recursive polymorphic types , 1984, Inf. Control..

[13]  A. Pitts INTRODUCTION TO HIGHER ORDER CATEGORICAL LOGIC (Cambridge Studies in Advanced Mathematics 7) , 1987 .

[14]  John C. Mitchell,et al.  On the Sequential Nature of Unification , 1984, J. Log. Program..

[15]  Mario Coppo,et al.  Principal type-schemes and lambda-calculus semantics , 1980 .

[16]  Gordon D. Plotkin,et al.  The category-theoretic solution of recursive domain equations , 1977, 18th Annual Symposium on Foundations of Computer Science (sfcs 1977).

[17]  John C. Mitchell,et al.  Polymorphic unification and ML typing , 1989, POPL '89.

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

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

[20]  John C. Reynolds,et al.  Using category theory to design implicit conversions and generic operators , 1980, Semantics-Directed Compiler Generation.

[21]  John C. Mitchell,et al.  Polymorphic Type Inference and Containment , 1988, Inf. Comput..

[22]  Ravi Sethi,et al.  A semantic model of types for applicative languages , 1982, LFP '82.

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

[24]  J. Roger Hindley,et al.  The Completeness Theorem for Typing lambda-Terms , 1983, Theor. Comput. Sci..

[25]  R. Hindley The Principal Type-Scheme of an Object in Combinatory Logic , 1969 .

[26]  Harry G. Mairson,et al.  Unification and ML-Type Reconstruction , 1991, Computational Logic - Essays in Honor of Alan Robinson.

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

[28]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[29]  J. Roger Hindley Curry's Type-Rules are Complete with Respect to the F-Semantics too , 1983, Theor. Comput. Sci..

[30]  Mariangiola Dezani-Ciancaglini,et al.  A filter lambda model and the completeness of type assignment , 1983, Journal of Symbolic Logic.

[31]  Daniel Leivant,et al.  Polymorphic type inference , 1983, POPL '83.