Abstract
Statically typed programming languages allow earlier error checking, better enforcement of diciplined programming styles, and the generation of more efficient object code than languages where all type consistency checks are performed at run time. However, even in statically typed languages, there is often the need to deal with datawhose type cannot be determined at compile time. To handle such situations safely, we propose to add a type Dynamic whose values are pairs of a value v and a type tag T where v has the type denoted by T. Instances of Dynamic are built with an explicit tagging construct and inspected with a type safe typecase construct.
This paper explores the syntax, operational semantics, and denotational semantics of a simple language that includes the type Dynamic. We give examples of how dynamically typed values can be used in programming. Then we discuss an operational semantics for our language and obtain a soundness theorem. We present two formulations of the denotational semantics of this language and relate them to the operational semantics. Finally, we consider the implications of polymorphism and some implementation issues.
- 1 ATKINSON, M. P., AND BUNEMAN, O. P. Types and persistence in database programming languages. Comput. Surv. 19, 2 (June 1987), 105-190. Google Scholar
- 2 ATKINSON, M. P., AND MORRISON, R. Polymorphic names and iterations. Draft article, Sept. 1987.Google Scholar
- 3 BARENDREGT, H.P. The Lambda Calculus. Rev. ed. North-Holland, Amsterdam, 1984.Google Scholar
- 4 BmR~LL, A. D., AND NELSON, B. J. Implementing remote procedure calls. ACM Trans. Comput. Syst. 2, i (Feb. 1984), 39-59. Google Scholar
- 5 BmTWISTLE, G. M., DAHL, 0. J., MYHRHAUG, B., AND NYGAARD, K. S~mula Begin. Studentlitteratur, Lund, Sweden, 1979.Google Scholar
- 6 BORRAS, P., CLEMENT, D., DESPEYROUX, T., INCERPI, J., KAHN, G., LANG, B., AND PASCUAL, V. CENTAUR: The system. In Proceedings of the 3rd Annual Symposium on Software Development Environments (SIGSOFT88) (Boston, Mass., Nov.). ACM, New York, 1988. Google Scholar
- 7 CARDELLI, L. Amber. In Combinators and Functional Programming Languages, G. Cousineau, P. L. Curien, and B. Robinet, Eds. Lecture Notes in Computer Science, vol. 242. Springer-Verlag, New York, 1986. Google Scholar
- 8 CARDELLI, L., AND MACQUEEN, D. Persistence and type abstraction. In Proceedings of the Persistence and Datatypes Workshop (St. Andrews, Scotland, Aug. 1985). Dept. of Computational Science, Univ. of St. Andrews, 1985 (Persistent Program. Res. Rep. 16).Google Scholar
- 9 CARDELLI, L., AND WEGNER, P. On understanding types, data abstraction, and polymorphism. Comput. Surv. 17, 4 (Dee. 1985), 471-522. Google Scholar
- 10 CARDELLI, L., DONAHUE, J., JORDAN, M., KALSOW, B., AND NELSON, G. The Modula-3 type system. In Proceedings of the 16th Annual ACM Symposium on Princ~ples of Programming Languages (Austin, Tex., Jan. 11-13, 1989). ACM, New York, pp. 202-212. Google Scholar
- 11 CARDELLI, L., DONAHUE, J., GLASSMAN, L., JORDAN, M., KALSOW, B., AND NELSON, G. Modula-3 report (revised). Res. rep. 52, DEC Systems Research Center, Palo Alto, Calif., Nov. 1989.Google Scholar
- 12 CHURCH, A. A formulation ofthe simple theory of types. J Symbohc Logic 5 (1940), 56-68.Google Scholar
- 13 CL~MENT, D., DESPEYROUX, J., DESPEYROUX, T., HASCOET, L., AND KAHN, G. Natural semantics on the computer. Tech. Rep. RR 416, INRIA, Sophia-Antipolis June 1985.Google Scholar
- 14 DESPEYROUX, T. Typoh A formalism to implement natural semanties. Teeh. Rep. 94, INRIA, Mar. 1988.Google Scholar
- 15 HARPER, R. Introduction fo Standard ML. Teeh. Rep. ECS-LFCS-86-14, Lab. for the Foundations of Computer Science, Edinburgh Univ., Edinburgh, Scotland, Sept. 1986.Google Scholar
- 16 HINDLEY, J. R., AND SELDIN, J. P. Introduction to Combinators and x-Calculus. London Mathematical Society Student Texts, vol. 1. Cambridge University Press, New York, 1986. Google Scholar
- 17 KAH~, G. Natural Semantics. Programming of Future Generation Computers, K. Fuchi and M. Nivat, Eds., Elsevier, (North-Holland), Amsterdam, 1988, pp. 237-258. Google Scholar
- 18 LAMPSON, B. A description of the Cedar language. Tech. Rep. CSL-8345, Xerox Pale Alto Research Center, Palo Alto, Calif., 1983.Google Scholar
- 19 LISKOV, B., ATKINSON, R., BLOOM, T, MOSS, E., SCHAFFERT, J. C., SCItEIFLER, R. AND SNYDER, A. CLU Reference Manual. Springer-Verlag, New York, 1981. Google Scholar
- 20 MACQUEEN, D., PLOTKIN, G., AND SETHI, e. An idea} model for recursive polymorphic types. Inf. Control, 71 (1986), 95-130. Google Scholar
- 21 MARTIN-L"F, P. Intitutionistic Type Theory. Bibliopolis, Naples, 1984.Google Scholar
- 22 McDONALD, D. B., FAHLMAN, S. E., AND WHOLEY, S. Internal design of CMU Common Lisp un the IBM RT PC. Tech. Rep. CMU-CS-87-157, Carnegie-Mellon Univ., School of Computer Science, Pittsburgh, Pa., Apr. 1988.Google Scholar
- 23 MILNER, R. A theory of type polymorphism in programming. J. Comput. Syst. Sci. 17 (Aug. 1978), 348-375.Google Scholar
- 24 MILNER, R., TOFTE, M., AND HARPER, R. The Definition of Standard ML. MIT Press, Cambridge, Mass., 1990. Google Scholar
- 25 MITCHELL, J., AND PLOTKIN, G. Abstract types have existential type. ACM Trans. Prograin. Lang. Syst. 10, 3 (July 1988), 470-502. Google Scholar
- 26 MYCROFT, A. Dynamic types in ML. Draft article, 1983.Google Scholar
- 27 NEWCOMER, J.M. Efficient binary I/O of IDL objects. SIGPLAN Not. (ACM) 22, 11 (Nov. 1987), 35-42. Google Scholar
- 28 PLOTKIN, G. Call-by-name, call-by-value, and the X-calculus. Theor. Comput. Sci. I (1975), 125-159.Google Scholar
- 29 PLOTKIN, G.D. A structural approach to operational semantics. Tech. Rep. DAIMI FN-19, Computer Science Dept., Aarhus Univ., Aarhus, Denmark, 1981.Google Scholar
- 30 RE~NOLDS, J. Three approaches to type structure. In Mathemat~cal Foundatlons of Software Development, H. Ehrig, C Florol, M. Nivat, and J. Thatcher, Eds. Lecture Notes in Computer Science, vol. 185. Springer-Verlag, New York, 1985. Google Scholar
- 31 ROVNER, P. On extending Modula-2 to build large, integrated systems IEEE Softw. 3, 6 (Nov. 1986), 46-57.Google Scholar
- 32 SCHAFFERT, J. C. A formal definition of CLU. Master's thesls, MIT, Dept. of Computer Science, Cambridge, Mass., Jan. 1978 (Tech. Rep. MIT/LCS/TR-193).Google Scholar
- 33 SCHEIFLER, R. W. A denotational semantics of CLU. Master's thesis, MIT, Cambridge, Mass., May 1978 (Tech. Rep. MIT/LCS/TR-201). Google Scholar
- 34 T~A~TE, S. R. Quasi-static typing (preliminary report), In Proceed~ngs of the 17th ACM Symposium on Principles ofProgramm~ng Languages. ACM, New York, 1990, pp. 367-381. Google Scholar
- 35 TOFTE, M. Operational semantics and polymorphic type inference. Ph.D. thesis, Computer Science Dept., Edinburgh Univ., Edinburgh, Scotland, 1988 (Tech. Rep. CST-52-88).Google Scholar
- 36 WEm, P., APO~TE, M.-V., LAWLLE, A., MAUXY, M., A~D SU~REZ, A. The CAML reference manual, Version 2.6. Tech. Rep., Projet Formel, INRIA-ENS, Paris, 1989.Google Scholar
Index Terms
- Dynamic typing in a statically typed language
Recommendations
Typing dynamic typing
ICFP '02: Proceedings of the seventh ACM SIGPLAN international conference on Functional programmingEven when programming in a statically typed language we every now and then encounter statically untypable values; such values result from interpreting values or from communicating with the outside world. To cope with this problem most languages include ...
Dynamic typing in a statically-typed language
POPL '89: Proceedings of the 16th ACM SIGPLAN-SIGACT symposium on Principles of programming languagesStatically-typed programming languages allow earlier error checking, better enforcement of disciplined programming styles, and generation of more efficient object code than languages where all type-consistency checks are performed at runtime. However, ...
Ad-hoc polymorphism and dynamic typing in a statically typed functional language
WGP '10: Proceedings of the 6th ACM SIGPLAN workshop on Generic programmingStatic typing in functional programming languages such as Clean, Haskell, and ML is highly beneficial: it prevents erroneous behaviour at run time and provides opportunities for optimisations. However, dynamic typing is just as important as sometimes ...
Comments