skip to main content
research-article

Logical types for untyped languages

Published:27 September 2010Publication History
Skip Abstract Section

Abstract

Programmers reason about their programs using a wide variety of formal and informal methods. Programmers in untyped languages such as Scheme or Erlang are able to use any such method to reason about the type behavior of their programs. Our type system for Scheme accommodates common reasoning methods by assigning variable occurrences a subtype of their declared type based on the predicates prior to the occurrence, a discipline dubbed occurrence typing. It thus enables programmers to enrich existing Scheme code with types, while requiring few changes to the code itself.

Three years of practical experience has revealed serious shortcomings of our type system. In particular, it relied on a system of ad-hoc rules to relate combinations of predicates, it could not reason about subcomponents of data structures, and it could not follow sophisticated reasoning about the relationship among predicate tests, all of which are used in existing code.

In this paper, we reformulate occurrence typing to eliminate these shortcomings. The new formulation derives propositional logic formulas that hold when an expression evaluates to true or false, respectively. A simple proof system is then used to determine types of variable occurrences from these propositions. Our implementation of this revised occurrence type system thus copes with many more untyped programming idioms than the original system.

Skip Supplemental Material Section

Supplemental Material

icfp-mon-1725-tobinhochstadt.mov

mov

144.1 MB

References

  1. }}A. Aiken, E. L. Wimmers, and T. K. Lakshman. Soft typing with conditional types. In Proc. 21st Symposium on Principles of Programming Languages, pages 163--173. ACM Press, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Y. Bertot and P. Castéran. Interactive Theorem Proving and Program Development, volume XXV of EATCS Texts in Theoretical Computer Science. Springer-Verlag, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. }}G. M. Bierman, A. D. Gordon, C. Hricu, and D. Langworthy. Semantic sub-typing with an SMT solver. In Proc. Fifteenth International Conference on Functional Programming. ACM Press, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. }}R. Cartwright. User-defined data types as an aid to verifying LISP programs. In International Conference on Automata, Languages and Programming, pages 228--256, 1976.Google ScholarGoogle Scholar
  5. }}K. Crary, S. Weirich, and G. Morrisett. Intensional polymorphism in type-erasure semantics. In Proc. Third International Conference on Functional Programming, pages 301--312. ACM Press, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. }}H. Curry and R. Feys. Combinatory Logic, volume I. North-Holland, 1958.Google ScholarGoogle Scholar
  7. }}ECMA. ECMAScript Edition 4 group wiki, 2007. URL http://wiki.ecmascript.org/.Google ScholarGoogle Scholar
  8. }}M. Felleisen, R. B. Findler, M. Flatt, and S. Krishnamurthi. How to Design Programs. MIT Press, 2001. URL http://www.htdp.org/.Google ScholarGoogle Scholar
  9. }}C. Flanagan and M. Felleisen. Componential set-based analysis. ACM Trans. Progr. Lang. Sys., 21(2):370--416, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}M. Flatt and PLT. Reference: Racket. Reference Manual PLT-TR2010-1. PLT Scheme, Inc. June 2010. http://racket-lang.org/techreports/.Google ScholarGoogle Scholar
  11. }}M. Furr, J.-h. D. An, J. S. Foster, and M. Hicks. Static type inference for ruby. In SAC '09: Proc. 2009 ACM Symposium on Applied Computing, pages 1859--1866. ACM Press, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}H. Ganzinger, G. Hagen, R. Nieuwenhuis, A. Oliveras, and C. Tinelli. DPLL(T): Fast Decision Procedures. In 16th International Conference on Computer Aided Verification, CAV'04, volume 3114 of Lecture Notes in Computer Science, pages 175--188. Springer-Verlag, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  13. }}F. Henglein. Dynamic typing: Syntax and proof theory. Sci. Comput. Programming, 22(3):197--230, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}F. Henglein and J. Rehof. Safe polymorphic type inference for a dynamically typed language: translating Scheme to ML. In Proc. Seventh International Conference on Functional Programming Languages and Computer Architecture, pages 192--203. ACM Press, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}W. A. Howard. The formulas-as-types notion of construction. In J. P. Seldin and J. Hindley, editors, To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus, and Formalism, pages 479--490. Academic Press. 1980.Google ScholarGoogle Scholar
  16. }}R. Komondoor, G. Ramalingam, S. Chandra, and J. Field. Dependent types for program understanding. In Tools and Algorithms for the Construction and Analysis of Systems, volume 3440 of Lecture Notes in Computer Science, pages 157--173. Springer-Verlag, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. }}J. M. Lucassen and D. K. Gifford. Polymorphic effect systems. In Proc. 15th Symposium on Principles of Programming Languages, pages 47--57. ACM Press, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. }}C. McBride and J. McKinna. The view from the left. Journal of Functional Programming, 14(1):69--111, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. }}U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007.Google ScholarGoogle Scholar
  20. }}S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In Proc. Eleventh International Conference on Functional Programming, pages 50--61. ACM Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. }}B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Progr. Lang. Sys., 22(1):1--44, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. }}J. C. Reynolds. Automatic computation of data set definitions. In IFIP Congress (1), pages 456--461, 1968.Google ScholarGoogle Scholar
  23. }}O. Shivers. Control-Flow Analysis of Higher-Order Languages or Taming Lambda. PhD thesis, Carnegie Mellon University, Pittsburgh, Pennsylvania, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. }}J. G. Siek and W. Taha. Gradual typing for functional languages. In Seventh Workshop on Scheme and Functional Programming, University of Chicago Technical Report TR-2006-06, pages 81--92, September 2006.Google ScholarGoogle Scholar
  25. }}V. Simonet and F. Pottier. A constraint-based approach to guarded algebraic data types. ACM Trans. Progr. Lang. Sys., 29(1):1--54, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. }}S. Thatte. Quasi-static typing. In Proc. 17th Symposium on Principles on Programming Languages, pages 367--381. ACM Press, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. }}S. Tobin-Hochstadt and M. Felleisen. The design and implementation of Typed Scheme. In Proc. 35th Symposium on Principles of Programming Languages, pages 395--406. ACM Press, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. }}D. Vytiniotis, S. Peyton Jones, and T. Schrijvers. Let should not be generalized. In TLDI '10: Proc. 5th workshop on Types in language design and implementation, pages 39--50. ACM Press, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. }}P. Wadler and R. B. Findler. Well-typed programs can't be blamed. In ESOP '09: Proc. Eighteenth European Symposium on Programming, volume 5502 of Lecture Notes in Computer Science, pages 1--16. Springer-Verlag, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. }}A. K. Wright and R. Cartwright. A practical soft type system for Scheme. ACM Trans. Progr. Lang. Sys., 19(1):87--152, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. }}T. Wrigstad, F. Z. Nardelli, S. Lebresne, J. Östlund, and J. Vitek. Integrating typed and untyped code in a scripting language. In Proc. 37th Symposium on Principles of Programming Languages, pages 377--388. ACM Press, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Logical types for untyped languages

    Recommendations

    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 45, Issue 9
      ICFP '10
      September 2010
      382 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1932681
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '10: Proceedings of the 15th ACM SIGPLAN international conference on Functional programming
        September 2010
        398 pages
        ISBN:9781605587943
        DOI:10.1145/1863543

      Copyright © 2010 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 27 September 2010

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    ePub

    View this article in ePub.

    View ePub