Gradual Typing for Functional Languages

Static and dynamic type systems have well-known strengths and weaknesses, and each is better suited for different programming tasks. There have been many efforts to integrate static and dynamic typing and thereby combine the benefits of both typing disciplines in the same language. The flexibility of static typing can be improved by adding a type Dynamic and a typecase form. The safety and performance of dynamic typing can be improved by adding optional type annotations or by performing type inference (as in soft typing). However, there has been little formal work on type systems that allow a programmer-controlled migration between dynamic and static typing. Thatte proposed Quasi-Static Typing, but it does not statically catch all type errors in completely annotated programs. Anderson and Drossopoulou defined a nominal type system for an object-oriented language with optional type annotations. However, developing a sound, gradual type system for functional languages with structural types is an open problem. In this paper we present a solution based on the intuition that the structure of a type may be partially known/unknown at compiletime and the job of the type system is to catch incompatibilities between the known parts of types. We define the static and dynamic semantics of a λ-calculus with optional type annotations and we prove that its type system is sound with respect to the simply-typed λ-calculus for fully-annotated terms. We prove that this calculus is type safe and that the cost of dynamism is “pay-as-you-go”.

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

[2]  J. Y. Girard,et al.  Interpretation fonctionelle et elimination des coupures dans l'aritmetique d'ordre superieur , 1972 .

[3]  Gordon D. Plotkin,et al.  Call-by-Name, Call-by-Value and the lambda-Calculus , 1975, Theor. Comput. Sci..

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

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

[6]  Guy L. Steele,et al.  An overview of COMMON LISP , 1982, LFP '82.

[7]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[8]  Martín Abadi,et al.  Dynamic typing in a statically-typed language , 1989, POPL '89.

[9]  Satish R. Thatte Quasi-static typing , 1989, POPL '90.

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

[11]  Craig Chambers,et al.  The cecil language: specification and rationale , 1993 .

[12]  Gilad Bracha,et al.  Strongtalk: typechecking Smalltalk in a production environment , 1993, OOPSLA '93.

[13]  Fritz Henglein,et al.  Dynamic Typing: Syntax and Proof Theory , 1994, Sci. Comput. Program..

[14]  Alberto Oliart An Algorithm for Inferring Quasi-Static Types , 1994 .

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

[16]  P. Tucker Withington,et al.  Dylan programming: an object-oriented and dynamic language , 1996 .

[17]  Andrew Shalit,et al.  The Dylan Reference Manual: The Definitive Guide to the New Object-Oriented Dynamic Language , 1996 .

[18]  Zhong Shao Flexible representation analysis , 1997, ICFP '97.

[19]  Geoffrey Smith,et al.  Eliminating covert flows with minimum typings , 1997, Proceedings 10th Computer Security Foundations Workshop.

[20]  Simon Peyton Jones,et al.  Proceedings of the second ACM SIGPLAN international conference on Functional programming , 1997, ICFP 1997.

[21]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[22]  Robert Hieb,et al.  Revised 5 Report on the Algorithmic Language , 1999 .

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

[24]  Lawrence Charles Paulson,et al.  Isabelle/HOL: A Proof Assistant for Higher-Order Logic , 2002 .

[25]  Tobias Nipkow,et al.  Structured Proofs in Isar/HOL , 2002, TYPES.

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

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

[28]  Sophia Drossopoulou,et al.  BabyJ: from object based to class based programming via types , 2003, WOOD.

[29]  Gilad Bracha Pluggable Type Systems , 2004 .

[30]  James Riely,et al.  Trust and Partial Typing in Open Systems of Mobile Agents , 2004, Journal of Automated Reasoning.

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

[32]  Matthias Felleisen,et al.  Semantic Casts: Contracts and Structural Subtyping in a Nominal World , 2004, ECOOP.

[33]  Compiling Scheme programs to . NET Common Intermediate Language , 2004 .

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

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

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

[37]  Cormac Flanagan,et al.  Hybrid type checking , 2006, POPL '06.

[38]  Walid Taha,et al.  Gradual Typing: Isabelle/Isar Formalization , 2006 .

[39]  William R. Cook,et al.  A virtual class calculus , 2006, POPL '06.