Principal Type Schemes for Gradual Programs

Gradual typing is a discipline for integrating dynamic checking into a static type system. Since its introduction in functional languages, it has been adapted to a variety of type systems, including object-oriented, security, and substructural. This work studies its application to implicitly typed languages based on type inference. Siek and Vachharajani designed a gradual type inference system and algorithm that infers gradual types but still rejects ill-typed static programs. However, the type system requires local reasoning about type substitutions, an imperative inference algorithm, and a subtle correctness statement. This paper introduces a new approach to gradual type inference, driven by the principle that gradual inference should only produce static types. We present a static implicitly typed language, its gradual counterpart, and a type inference procedure. The gradual system types the same programs as Siek and Vachharajani, but has a modular structure amenable to extension. The language admits let-polymorphism, and its dynamics are defined by translation to the Polymorphic Blame Calculus. The principal types produced by our initial type system mask the distinction between static parametric polymorphism and polymorphism that can be attributed to gradual typing. To expose this difference, we distinguish static type parameters from gradual type parameters and reinterpret gradual type consistency accordingly. The resulting extension enables programs to be interpreted using either the polymorphic or monomorphic Blame Calculi.

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

[2]  Simon L. Peyton Jones,et al.  Practical type inference for arbitrary-rank types , 2007, Journal of Functional Programming.

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

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

[5]  Juan Chen,et al.  Gradual typing embedded securely in JavaScript , 2014, POPL.

[6]  David Crystal,et al.  A dictionary of linguistics and phonetics , 1997 .

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

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

[9]  Walid Taha,et al.  Exploring the Design Space of Higher-Order Casts , 2009, ESOP.

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

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

[12]  Éric Tanter,et al.  Gradual Typestate , 2011, ECOOP.

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

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

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

[16]  Manish Vachharajani,et al.  Gradual typing with unification-based inference , 2008, DLS '08.

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

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

[19]  Stephen N. Freund,et al.  Sage: Hybrid Checking for Flexible Specifications , 2006 .

[20]  Dave Clarke,et al.  Gradual Ownership Types , 2012, ESOP.

[21]  Avik Chaudhuri,et al.  The ins and outs of gradual type inference , 2012, POPL '12.

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

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

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

[25]  Saumya K. Debray,et al.  Automatic Mode Inference for Logic Programs , 1988, J. Log. Program..

[26]  Philip Wadler,et al.  Well-Typed Programs Can't Be Blamed , 2009, ESOP.

[27]  Andrew K. Wright Simple imperative polymorphism , 1995, LISP Symb. Comput..

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

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