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.
Supplemental Material
- }}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 ScholarDigital Library
- }}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 ScholarDigital Library
- }}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 ScholarDigital Library
- }}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 Scholar
- }}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 ScholarDigital Library
- }}H. Curry and R. Feys. Combinatory Logic, volume I. North-Holland, 1958.Google Scholar
- }}ECMA. ECMAScript Edition 4 group wiki, 2007. URL http://wiki.ecmascript.org/.Google Scholar
- }}M. Felleisen, R. B. Findler, M. Flatt, and S. Krishnamurthi. How to Design Programs. MIT Press, 2001. URL http://www.htdp.org/.Google Scholar
- }}C. Flanagan and M. Felleisen. Componential set-based analysis. ACM Trans. Progr. Lang. Sys., 21(2):370--416, 1999. Google ScholarDigital Library
- }}M. Flatt and PLT. Reference: Racket. Reference Manual PLT-TR2010-1. PLT Scheme, Inc. June 2010. http://racket-lang.org/techreports/.Google Scholar
- }}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 ScholarDigital Library
- }}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 ScholarCross Ref
- }}F. Henglein. Dynamic typing: Syntax and proof theory. Sci. Comput. Programming, 22(3):197--230, 1994. Google ScholarDigital Library
- }}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 ScholarDigital Library
- }}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 Scholar
- }}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 ScholarDigital Library
- }}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 ScholarDigital Library
- }}C. McBride and J. McKinna. The view from the left. Journal of Functional Programming, 14(1):69--111, 2004. Google ScholarDigital Library
- }}U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007.Google Scholar
- }}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 ScholarDigital Library
- }}B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Progr. Lang. Sys., 22(1):1--44, 2000. Google ScholarDigital Library
- }}J. C. Reynolds. Automatic computation of data set definitions. In IFIP Congress (1), pages 456--461, 1968.Google Scholar
- }}O. Shivers. Control-Flow Analysis of Higher-Order Languages or Taming Lambda. PhD thesis, Carnegie Mellon University, Pittsburgh, Pennsylvania, 1991. Google ScholarDigital Library
- }}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 Scholar
- }}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 ScholarDigital Library
- }}S. Thatte. Quasi-static typing. In Proc. 17th Symposium on Principles on Programming Languages, pages 367--381. ACM Press, 1990. Google ScholarDigital Library
- }}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 ScholarDigital Library
- }}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 ScholarDigital Library
- }}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 ScholarDigital Library
- }}A. K. Wright and R. Cartwright. A practical soft type system for Scheme. ACM Trans. Progr. Lang. Sys., 19(1):87--152, 1997. Google ScholarDigital Library
- }}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 ScholarDigital Library
Index Terms
- Logical types for untyped languages
Recommendations
Logical types for untyped languages
ICFP '10: Proceedings of the 15th ACM SIGPLAN international conference on Functional programmingProgrammers 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 ...
Adding types to untyped languages
TLDI '10: Proceedings of the 5th ACM SIGPLAN workshop on Types in language design and implementationOver the last 15 years, we have experienced a programming language renaissance. Numerous scripting languages have become widely used in industrial and open-source projects. They have supplemented the existing mainstream languages--C++ and Java--and, in ...
Modeling abstract types in modules with open existential types
POPL '09We propose F-zip, a calculus of open existential types that is an extension of System F obtained by decomposing the introduction and elimination of existential types into more atomic constructs. Open existential types model modular type abstraction as ...
Comments