Logical types for untyped languages

Programmers reason about their programs using a wide variety of formal and informal methods. Programmers in untyped languages such as Scheme or Erlang are able to use any such method to reason about the type behavior of their programs. Our type system for Scheme accommodates common reasoning methods by assigning variable occurrences a subtype of their declared type based on the predicates prior to the occurrence, a discipline dubbed occurrence typing. It thus enables programmers to enrich existing Scheme code with types, while requiring few changes to the code itself. Three years of practical experience has revealed serious shortcomings of our type system. In particular, it relied on a system of ad-hoc rules to relate combinations of predicates, it could not reason about subcomponents of data structures, and it could not follow sophisticated reasoning about the relationship among predicate tests, all of which are used in existing code. In this paper, we reformulate occurrence typing to eliminate these shortcomings. The new formulation derives propositional logic formulas that hold when an expression evaluates to true or false, respectively. A simple proof system is then used to determine types of variable occurrences from these propositions. Our implementation of this revised occurrence type system thus copes with many more untyped programming idioms than the original system.

[1]  Pierre Castéran,et al.  Interactive Theorem Proving and Program Development , 2004, Texts in Theoretical Computer Science An EATCS Series.

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

[3]  John C. Reynolds,et al.  Automatic computation of data set definitions , 1968, IFIP Congress.

[4]  Cesare Tinelli,et al.  DPLL( T): Fast Decision Procedures , 2004, CAV.

[5]  Simon L. Peyton Jones,et al.  Let should not be generalized , 2010, TLDI '10.

[6]  Matthias Felleisen,et al.  Componential set-based analysis , 1997, TOPL.

[7]  Haskell B. Curry,et al.  Combinatory Logic, Volume I , 1959 .

[8]  Robert Cartwright,et al.  User-Defined Data Types as an Aid to Verifying LISP Programs , 1976, ICALP.

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

[10]  Andrew D. Gordon,et al.  Semantic subtyping with an SMT solver , 2010, ICFP '10.

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

[12]  William A. Howard,et al.  The formulae-as-types notion of construction , 1969 .

[13]  U. Norell,et al.  Towards a practical programming language based on dependent type theory , 2007 .

[14]  Karl Crary,et al.  Intensional polymorphism in type-erasure semantics , 1998, ICFP '98.

[15]  Fritz Henglein,et al.  Safe polymorphic type inference for a dynamically typed language: translating Scheme to ML , 1995, FPCA '95.

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

[17]  Olin Shivers,et al.  Control-flow analysis of higher-order languages of taming lambda , 1991 .

[18]  P. Medawar A view from the left , 1984, Nature.

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

[20]  David K. Gifford,et al.  Polymorphic effect systems , 1988, POPL '88.

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

[22]  Alexander Aiken,et al.  Soft typing with conditional types , 1994, POPL '94.

[23]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

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

[25]  Satish Chandra,et al.  Dependent Types for Program Understanding , 2005, TACAS.

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

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

[28]  François Pottier,et al.  A constraint-based approach to guarded algebraic data types , 2007, TOPL.

[29]  Benjamin C. Pierce,et al.  Local type inference , 1998, POPL '98.

[30]  Matthias Felleisen,et al.  How to Design Programs , 2001 .