Dynamic typing as staged type inference

Dynamic typing extends statically typed languages with a universal datatype, simplifying programs which must manipulate other programs as data, such as distributed, persistent, interpretive and generic programs. Current approaches, however, limit the use of polymorphism in dynamic values, and can be syntactically awkward.We introduce a new approach to dynamic typing, based on staged computation, which allows a single type-reconstruction algorithm to execute partly at compile time and partly at run-time. This approach seamlessly extends a single type system to accommodate types that are only known at run-time, while still supporting both type inference and polymorphism. The system is significantly more expressive than other approaches. Furthermore it can be implemented efficiently; most of the type inference is done at compile-time, leaving only some residual unification for run-time.We demonstrate our approach by examples in a small polymorphic functional language, and present its type system, type reconstruction algorithm, and operational semantics. Our proposal could also be readily adapted to many other programming languages.

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

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

[3]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997, PEPM.

[4]  Hendrik Pieter Barendregt,et al.  Introduction to generalized type systems , 1991, Journal of Functional Programming.

[5]  Flemming Nielson,et al.  Two-level functional languages , 1992, Cambridge tracts in theoretical computer science.

[6]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

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

[8]  Alexander Aiken,et al.  Type inclusion constraints and type inference , 1993, FPCA '93.

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

[10]  Xavier Leroy,et al.  Dynamics in ML , 1991, Journal of Functional Programming.

[11]  Malcolm P. Atkinson,et al.  An orthogonally persistent Java , 1996, SGMD.

[12]  Rowan Davies,et al.  A temporal-logic approach to binding-time analysis , 1995, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[13]  Olivier Danvy,et al.  Thunks and the lambda-Calculus , 1997, J. Funct. Program..

[14]  Eugenio Moggi,et al.  A categorical account of two-level languages , 1997, MFPS.

[15]  Simon L. Peyton Jones,et al.  State in Haskell , 1995, LISP Symb. Comput..

[16]  Martin Odersky,et al.  Putting type annotations to work , 1996, POPL '96.

[17]  Martín Abadi,et al.  Dynamic typing in polymorphic languages , 1995, Journal of Functional Programming.

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

[19]  Luca Cardelli,et al.  An Extension of System F with Subtyping , 1991, TACS.

[20]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997 .

[21]  Peter Lee,et al.  Optimizing ML with run-time code generation , 1996, PLDI '96.

[22]  Olivier Danvy,et al.  Thunks and the λ-calculus , 1997, Journal of Functional Programming.

[23]  Simon Thompson,et al.  Type theory and functional programming , 1991, International computer science series.

[24]  Frank Pfenning,et al.  A modal analysis of staged computation , 1996, POPL '96.

[25]  Wolfgang Klas,et al.  Persistence in the Object-Oriented Database Programming Language VML , 1992 .

[26]  Jean-Yves Girard,et al.  The System F of Variable Types, Fifteen Years Later , 1986, Theor. Comput. Sci..

[27]  WadlerPhilip,et al.  Report on the programming language Haskell , 1992 .

[28]  Pierre Weis,et al.  Extensional polymorphism , 1995, POPL 1995.

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

[30]  John C. Mitchell,et al.  Abstract types have existential type , 1988, TOPL.

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