article

Soft typing

Published:01 April 2004Publication History

Abstract

Type systems are designed to prevent the improper use of program operations. They can be classified as either static or dynamic depending on when they detect type errors. Static type systems detect potential type errors at compile-time and prevent program execution. Dynamic type systems detect type errors at run-time and abort program execution.Static type systems have two important advantages over dynamic type systems. First, they help programmers detect a large class of program errors before execution. Second, they extract information that a compiler can exploit to produce more efficient code. The price paid for these advantages, however, is a loss of expressiveness, generality, and semantic simplicity.This paper presents a generalization of static and dynamic typing---called soft typing---that combines the best features of both approaches. The key idea underlying soft typing is that a static type checker need not reject programs that contain potential type errors. Instead, the type checker can insert explicit run-time checks around "suspect" arguments of primitive operations, converting dynamically typed programs into statically type-correct form. The inserted run-time checks identify program phrases that may be erroneous. For soft typing to be effective, the type system must avoid inserting unnecessary run-time checks. To accomplish this objective, we have developed an extension of the ML type system supporting union types and recursive types that assigns types to a wider class of programs than ML. We have also developed an algorithm for frugally inserting run-time checks in programs that do not type check.

References

  1. Alain Colmerauer. Prolog and infinite trees. In K. L. Clark and S. A. Tarnlund, editors, Logic Programming, pages 231--251. Academic Press, 1982.Google ScholarGoogle Scholar
  2. Luis Damas and Robin Milner. Principal type-schemes for functional programs. In Conference Record of the Ninth Annual ACM Symposium on Principles of Programming Languages, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. C. Flanagan, M. Flatt, S. Krishnamurthi, S. Weirich, and M. Felleisen. Catching bugs in the web of program invariants. In Proceedings of the 1996 Conference on Programming Language Design and Implementation (PLDI), 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  5. F. Pessaux and X. Leroy. Type-based analysis of uncaught exceptions. In Symposium on the Principles of Programming Languages, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Didier Rémy. Typechecking records and variants in a natural extension of ml. In Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. R. A. Tapia. On the role of slack variables in quasi-newton methods for unconstrained optimization. In Numerical Optimization of Dynamical Systems. L. C. W. Dixon, 1980.Google ScholarGoogle Scholar
  8. Mads Tofte. Operational Semantics and Polymorphic Type Inference. PhD thesis, University of Edinburgh, 1987.Google ScholarGoogle Scholar
  9. A. Wright and R. Cartwright. A practical soft type system for Scheme. In Proceedings of Conference on LISP and functional Programming, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Martin Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically typed language. In Proceedings of the Sixteenth POPL Symposium, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Alexander Aiken and Brian Murphy. Static type inference in a dynamically typed language. In Proceedings of the 18th Annual Symposium on Principles of Programming Languages, 1991. To appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Andrew W. Appel and David MacQueen. Standard ML of New Jersey Reference Manual. (in preparation), 1990.Google ScholarGoogle Scholar
  13. Robert Cartwright. A constructive alternative to axiomatic data type definitions. In Proceedings of 1980 LISP Conference, 1980. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. William Clinger and Jonathan Rees. Revised3.99Report on the Algorithmic Language Scheme, August 1990.Google ScholarGoogle Scholar
  15. Alain Colmerauer. Prolog and infinite trees. In K. L. Clark and S. A. Tarnlund, editors, Logic Programming, pages 231--251. Academic Press, 1982.Google ScholarGoogle Scholar
  16. Pavel Curtis. Constrained quantification in polymorphic type analysis. Technical Report CSL-90-1, Xerox PARC, 1990.Google ScholarGoogle Scholar
  17. Luis Damas and Robin Milner. Principal type-schemes for functional programs. In Conference Record of the Ninth Annual ACM Symposium on Principles of Programming Languages, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Luis Manuel Martins Damas. Type Assignment in Programming Languages. PhD thesis, University of Edinburgh, 1985.Google ScholarGoogle Scholar
  19. Bruce F. Duba, Robert Harper, and David MacQueen. Typing first-class continuations in ML. In Conference Record of the Eighteenth Annual ACM Symposium on Principles of Programming Languages, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Mike Fagan. Soft Typing: An Approach to Type Checking for Dynamically Typed Languages. PhD thesis, Rice University, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. You-Chin Fuh and Prateek Mishra. Type inference with subtypes. In Conference Record of the European Symposium on Programming, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. You-Chin Fuh and Prateek Mishra. Polymorphic subtype inference: Closing the theory-practice gap. In TAPSOFT, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Carsten K. Gomard. Partial type inference for untyped functional programs. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Gérard Huet. Résolution d'équations dans les langages d'ordre 1,2,.., ω. PhD thesis, Université Paris, 7 1976.Google ScholarGoogle Scholar
  25. D. MacQueen, G. Plotkin, and R. Sethi. An ideal model for recursive polymorphic types. In Conference Record of the Eleventh Annual ACM Symposium on Principles of Programming Languages, 1983. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. D. B. MacQueen and Ravi Sethi. A semantic model of types for applicative languages. In Conference Record of the Tenth Annual ACM Symposium on Principles of Programming Languages, 1982.Google ScholarGoogle ScholarCross RefCross Ref
  27. Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  28. Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. John C. Mitchell. Coercion and type inference. In Conference Record of the Eleventh Annual ACM Symposium on Principles of Programming Languages, 1983. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Dider Rémy. Typechecking records and variants in a natural extension of ml. In Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. David A Schmidt. Denotational Semantics. Allyn and Bacon, Inc, 1986.Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Sattish Thatte. Quasi-static typing. In Proceedings of the Seventeenth POPL Symposium, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Mads Tofte. Operational Semantics and Polymorphic Type Inference. PhD thesis, University of Edinburgh, 1987.Google ScholarGoogle Scholar
  34. Mitchell Wand. Complete type inference for simple objects. In Proceedings of the Second Symposium on Logic in Computer Science, 1987.Google ScholarGoogle Scholar

Comments

Login options

Check if you have access through your login credentials or your institution to get full access on this article.

Sign in

Full Access

  • Published in

    cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 39, Issue 4
    20 Years of the ACM SIGPLAN Conference on Programming Language Design and Implementation 1979-1999: A Selection
    April 2004
    673 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/989393
    Issue’s Table of Contents

    Copyright © 2004 Authors

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    • Published: 1 April 2004

    Check for updates

    Qualifiers

    • article

PDF Format

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader
About Cookies On This Site

We use cookies to ensure that we give you the best experience on our website.

Learn more

Got it!