Dynamic typing in a statically typed language

  • Authors:
  • Martín Abadi;Luca Cardelli;Benjamin Pierce;Gordon Plotkin

  • Affiliations:
  • Digital Equipment Corp.;Digital Equipment Corp.;Carnegie-Mellon Univ., Pittsburgh, PA;Univ. of Edinburgh, Edinburgh, Scotland, UK

  • Venue:
  • ACM Transactions on Programming Languages and Systems (TOPLAS)
  • Year:
  • 1991

Quantified Score

Hi-index 0.00

Visualization

Abstract

Statically typed programming languages allow earlier errorchecking, better enforcement of diciplined programming styles, and thegeneration of more efficient object code than languages where all typeconsistency checks are performed at run time. However, even instatically typed languages, there is often the need to deal with datawhose type cannot be determined at compile time. To handlesuch situations safely, we propose to add a typeDynamic whose values are pairs of a valuev and a type tagT where vhas the type denoted by T. Instances ofDynamic are built with an explicittagging construct and inspected with a type safetypecase construct.This paper explores the syntax, operational semantics, and denotational semantics of a simple language that includes the typeDynamic. We give examples of howdynamically typed values can be used in programming. Then we discuss anoperational semantics for our language and obtain a soundness theorem. Wepresent two formulations of the denotational semantics of this languageand relate them to the operational semantics. Finally, we consider theimplications of polymorphism and some implementation issues.