Dynamic Typing

We present an extension of a statically typed language with a special type Dynamic and explicit type tagging and checking operations (coercions). Programs in run-time typed languages are viewed as incomplete programs that are to be completed to well-typed programs by explicitly inserting coercions into them. Such completions are generally not unique. If the meaning of an incomplete program is to be the meaning of any of its completions and if it is too be unambiguous it is necessary that all its completions are coherent (semantically equivalent). We characterize with an equational theory the properties a semantics must satisfy to be coherent. Since “naive” coercion evaluation does not satisfy all of the coherence equations we exclude certain “unsafe” completions from consideration that can cause avoidable type errors at run-time. Various classes of completions may be used, parameterized by whether or not coercions may only occur at data creation and data use points in a program and whether only primitive coercions or also induced coercions. For each of these classes any term has a minimal completion that is optimal in the sense that it contains no coercions that could be avoided by a another coercion in the same class. In particular, minimal completions contain no coercions at all whenever the program is statically typable. If only primitive type operations are admitted we show that minimal completions can be computed in almost-linear time. If induced coercions are also allowed the minimal completion can be computed in time O(nm) where n is the size of the program and m is the size of the value flow graph of the program, which may be of size O(n), but is typically rather sparse. Finally, we sketch how this explicit dynamic typing discipline can be extended to letpolymorphism by parameterization with respect to coercions. The resulting language framework leads to a seamless integration of statically typed and dynamically typed languages by relying on type inference for programs that have no type information and no explicit coercions whatsoever.

[1]  Satish R. Thatte,et al.  Type Inference with Partial Types , 1988, Theor. Comput. Sci..

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

[3]  Carsten K. Gomard Partial type inference for untyped functional programs , 1990, LISP and Functional Programming.

[4]  Zvi Galil,et al.  Data structures and algorithms for disjoint set union problems , 1991, CSUR.

[5]  Thierry Coquand,et al.  Inheritance as Implicit Coercion , 1991, Inf. Comput..

[6]  Mitchell Wand,et al.  Type Inference for Partial Types is Decidable , 1992, ESOP.

[7]  Peter Z. Revesz,et al.  On the Relationship of Congruence Closure and Unification , 1989, DBPL.

[8]  Benjamin C. Pierce,et al.  Bounded quantification is undecidable , 1992, POPL '92.

[9]  Peter Sestoft,et al.  Replacing function parameters by global variables , 1989, FPCA.

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

[11]  Giorgio Ghelli,et al.  Coherence of Subsumption , 1990, CAAP.

[12]  Fritz Henglein,et al.  Fast Left-Linear Semi-Unification , 1991, ICCI.

[13]  Marvin V. Zelkowitz,et al.  Programming Languages: Design and Implementation , 1975 .

[14]  Jan van Leeuwen,et al.  Maintenance of Transitive Closures and Transitive Reductions of Graphs , 1987, WG.

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

[16]  Prateek Mishra,et al.  Type Inference with Subtypes , 1990, Theor. Comput. Sci..

[17]  Robert E. Tarjan,et al.  Data structures and network algorithms , 1983, CBMS-NSF regional conference series in applied mathematics.

[18]  Thierry Coquand,et al.  Inheritance and explicit coercion , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.

[19]  Fritz Henglein,et al.  Efficient Type Inference for Higher-Order Binding-Time Analysis , 1991, FPCA.

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

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

[22]  Daniel M. Yellin,et al.  A dynamic transitive closure algorithm , 1988 .

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