Abstract
We present an extension of a statically typed language with a special type dyn 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 2), but is typically rather sparse.
Finally, we sketch how this explicit dynamic typing discipline can be extended to let-polymorphism 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.
This research has been supported by Esprit BRA 3124, Semantique.
Chapter PDF
Similar content being viewed by others
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
References
M. Abadi, L. Cardelli, B. Pierce, and G. Plotkin. Dynamic typing in a statically-typed language. In Proc. 16th Annual ACM Symp. on Principles of Programming Languages, pages 213–227, ACM, Jan. 1989.
M. Abadi, L. Cardelli, B. Pierce, and G. Plotkin. Dynamic typing in a statically typed language. ACM Transactions on Programming Languages and Systems (TOPLAS), 13(2):237–268, April 1991. Presented at POPL '89.
V. Breazu-Tannen, T. Coquand, C. Gunter, and A. Scedrov. Inheritance and explicit coercion. In Proc. Logic in Computer Science (LICS), pages 112–129, 1989.
V. Breazu-Tannen, T. Coquand, C. Gunter, and A. Scedrov. Inheritance as implicit coercion. Information and Computation, 93(1):172–221, July 1991. Presented at LICS '89.
R. Cartwright and M. Fagan. Soft typing. In Proc. ACM SIGPLAN '91 Conf. on Programming Language Design and Implementation, Toronto, Ontario, pages 278–292, ACM, ACM Press, June 1991.
P. Curien and G. Ghelli. Coherence of subsumption. In A. Arnold, editor, Proc. 15th Coll. on Trees in Algebra and Programming, Copenhagen, Denmark, pages 132–146, Springer, May 1990.
Y. Fuh and P. Mishra. Type inference with subtypes. In Proc. 2nd European Symp. on Programming, pages 94–114, Springer-Verlag, 1988. Lecture Notes in Computer Science 300.
Z. Galil and G. Italiano. Data structures and algorithms for disjoint set union problems. ACM Computing Surveys, 23(3):319–344, Sept. 1991.
C. Gomard. Partial type inference for untyped functional programs (extended abstract). In Proc. LISP and Functional Programming (LFP), Nice, France, July 1990.
F. Henglein. Fast left-linear semi-unification. In Proc. Int'l. Conf. on Computing and Information, Springer, May 1990. Lecture Notes of Computer Science, Vol. 468.
F. Henglein. Efficient type inference for higher-order binding-time analysis. In Proc. Conf. on Functional Programming Languages and Computer Architecture (FPCA), Cambridge, Massachusetts, pages 448–472, Springer, Aug. 1991. Lecture Notes in Computer Science, Vol. 523.
P. Kanellakis and P. Revesz. On the Relationship of Congruence Closure and Unification, chapter 2, pages 23–41. Frontier Series, Addison-Wesley, ACM Press, 1990.
X. Leroy and M. Mauny. Dynamics in ML. In Proc. Conf. on Functional Programming Languages and Computer Architecture (FPCA), Cambridge, Massachusetts, pages 406–426, Springer, Aug. 1991. Lecture Notes in Computer Science, Vol. 523.
J. La Poutré and J. van Leeuwen. Maintenance of transitive closures and transitive reductions of graphs. In Proc. Int'l Workshop on Graph-Theoretic Concepts in Computer Science, pages 106–120, Springer-Verlag, June 1987. Lecture Notes in Computer Science, Vol. 314.
R. Milner. A theory of type polymorphism in programming. J. Computer and System Sciences, 17:348–375, 1978.
A. Mycroft. Dynamic types in statically typed languages. Aug. 1984. Unpublished manuscript, 2nd draft version.
P. O'Keefe and M. Wand. Type inference for partial types is decidable. Sept. 1991. Submitted to ESOP '92.
B. Pierce. Bounded Quantification is Undecidable. Technical Report CMU-CS-91-161, Carnegie Mellon University, July 1991. To be presented at POPL '92.
D. Remy. Typechecking records and variants in a natural extension of ML. In Proc. 16th Annual ACM Symp. on Principles of Programming Languages, pages 77–88, ACM, Jan. 1989.
P. Sestoft. Replacing function parameters by global variables. In Proc. Functional Programming Languages and Computer Architecture (FPCA), London, England, pages 39–53, ACM Press, Sept. 1989.
R. Tarjan. Data Structures and Network Flow Algorithms. Volume CMBS 44 of Regional Conference Series in Applied Mathematics, SIAM, 1983.
S. Thatte. Type inference with partial types. In Proc. Int'l Coll. on Automata, Languages and Programming (ICALP), pages 615–629, 1988.
S. Thatte. Quasi-static typing. In Proc. ACM Symp. on Principles of Programming Languages, pages 367–381, ACM, Jan. 1990.
D. Yellin. A Dynamic Transitive Closure Algorithm. Technical Report RC 13535, IBM T.J. Watson Research Ctr., June 1988.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1992 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Henglein, F. (1992). Dynamic typing. In: Krieg-Brückner, B. (eds) ESOP '92. ESOP 1992. Lecture Notes in Computer Science, vol 582. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-55253-7_14
Download citation
DOI: https://doi.org/10.1007/3-540-55253-7_14
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-55253-6
Online ISBN: 978-3-540-46803-5
eBook Packages: Springer Book Archive