Abstract
In object-oriented programs, objects often provide methods whose parameter types or return types are the object types themselves. For example, the parameter types of binary methods are the types of their receiver objects, and the return types of some factory methods are the types of their enclosing objects. However, most object-oriented languages do not support such methods precisely because their type systems do not support explicit recursive types, which lead to a mismatch between subclassing and subtyping. This mismatch means that an expression of a subclass may not always be usable in a context where an expression of a superclass is expected, which is not intuitive in an object-oriented setting. Researchers have proposed various type-sound approaches to support methods with types of their enclosing object types denoted by some variants of ThisType, but they reject reasonable and useful methods due to unpermissive type systems or they use less precise declared inexact types rather than runtime exact types.
In this article, we present a thorough approach to support methods with ThisTypes: from a new encoding of objects in a typed lambda calculus that allows subtyping by subclassing to an open-source implementation as an extension of the Java programming language. We first provide real-world examples that motivate the need for ThisTyped methods to precisely describe desired properties of programs. We define a new object encoding that enables subtyping by subclassing even in the presence of negative occurrences of type recursion variables by distinguishing object types from existential object types. Based on this object encoding, we formalize language features to support ThisTyped methods with a core calculus CoreThisJava, and prove its type soundness. Finally, we provide ThisJava, a prototype implementation of the calculus, to show its backward compatibility, and we make it publicly available. We believe that our approach theoretically expands the long pursuit of an object-oriented language with ThisTypes to support more useful methods with more precise types.
- Martín Abadi and Luca Cardelli. 1996a. On subtyping and matching. ACM Transactions on Programming Languages and Systems 18, 4 (July 1996), 401--423. Google Scholar
Digital Library
- Martin Abadi and Luca Cardelli. 1996b. A Theory of Objects. Springer-Verlag, New York, Inc. Google Scholar
Digital Library
- Algred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. 2006. Compilers Principles, Techniques, & Tools (2nd. ed.). Addison Wesley. Google Scholar
Digital Library
- Eric Allen, David Chase, J. J. Hallett, Victor Luchangco, Jan-Willem Maessen, Sukyoung Ryu, Guy L. Steele, Jr., and Sam Tobin-Hochstadt. 2008. The Fortress Language Specification Version 1.0. (March 2008).Google Scholar
- Philippe Altherr and Vincent Cremet. 2007. Adding type constructor parameterization to java. In Proceedings of the 9th Workshop on Formal Techniques for Java-like Programs.Google Scholar
- Ken Arnold, James Gosling, and David Holmes. 2005. The Java™ Programming Language (4th. ed.). Addison-Wesley.Google Scholar
- SungGyeong Bae, Hyunghun Cho, Inho Lim, and Sukyoung Ryu. 2014. SAFEWAPI: Web API misuse detector for web applications. In Proceedings of the 2014 10th Joint Meeting on Foundations of Software Engineering. ACM. Google Scholar
Digital Library
- Kim Bruce. 1994. A paradigmatic object-oriented programming language: Design, static typing and semantics. Journal of Functional Programming 4, 2 (April 1994), 127--206.Google Scholar
Cross Ref
- Kim Bruce, Luca Cardelli, Giuseppe Castagna, Gary T. Leavens, and Benjamin Pierce. 1995. On binary methods. Theory and Practice of Object Systems 1, 3 (December 1995), 221--242. Google Scholar
Digital Library
- Kim B. Bruce, Luca Cardelli, and Benjamin C. Pierce. 1997. Comparing object encodings. In Theoretical Aspects of Computer Software. Vol. 1281. 415--438. Google Scholar
Digital Library
- Kim Bruce and J. Nathan Foster. 2004. LOOJ: Weaving LOOM into java. In Proceedings of the 18th European Conference on Object-Oriented Programming. 389--413.Google Scholar
- Kim Bruce, Martin Odersky, and Philip Wadler. 1998. A statically safe alternative to virtual types. In Proceedings of the 12th European Conference on Object-Oriented Programming. 523--549. Google Scholar
Digital Library
- Kim Bruce, Leaf Petersen, and Adrian Fiech. 1997. Subtyping is not a good “match” for object-oriented languages. In Proceedings of the 11th European Conference on Object-Oriented Programming. 104--127.Google Scholar
Cross Ref
- Kim Bruce, Angela Schuett, Robert van Gent, and Adrian Fiech. 2003. PolyTOIL: A type-safe polymorphic object-oriented language. ACM Transactions on Programming Languages and Systems 25, 2 (March 2003), 225--290. Google Scholar
Digital Library
- Kim B. Bruce. 1997. Increasing Java’s Expressiveness with ThisType and Match-Bounded Polymorphism. Technical Report. Williams College.Google Scholar
- Nicholas Cameron, Sophia Drossopoulou, and Erik Ernst. 2008. A model for java with wildcards. In Proceedings of the 18th European Conference on Object-Oriented Programming. Google Scholar
Digital Library
- Nicholas Cameron, Erik Ernst, and Sophia Drossopoulou. 2007. Towards an existential types model for java wildcards. In Proceedings of the 9th Workshop on Formal Techniques for Java-like Programs.Google Scholar
- Peter Canning, William Cook, Walter Hill, Walter Olthoff, and John C. Mitchell. 1989. F-bounded polymorphism for object-oriented programming. In Proceedings of the 4th International Conference on Functional Programming Languages and Computer Architecture. ACM, 273--280. Google Scholar
Digital Library
- Luca Cardelli. 1984. A semantics of multiple inheritance. In Proceedings of the International Symposium on Semantics of Data Types. 51--67. Google Scholar
Digital Library
- Luca Cardelli. 1986. Amber. In Proceedings of the 13th Spring School of the LITP on Combinators and Functional Programming Languages. 21--47. Google Scholar
Digital Library
- William R. Cook. 1989. A proposal for making Eiffel type-safe. Computer Journal 32, 4 (July 1989), 305--311. Google Scholar
Digital Library
- William R. Cook, Walter Hill, and Peter S. Canning. 1990. Inheritance is not subtyping. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 125--135. Google Scholar
Digital Library
- Patrick Cousot and Radhia Cousot. 1977. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Proceedings of the 4th ACM Symposium on Principles of Programming Languages. 238--252. Google Scholar
Digital Library
- Ecma. 2011. ECMAScript Language Specification. Edition 5.1. Retrieved from http://www.ecma-international.org/publications/standards/Ecma-262.htm.Google Scholar
- Jonathan Eifrig, Scott Smith, Valery Trifonov, and Amy Zwarico. 1995. An interpretation of typed OOP in a language with state. LISP and Symbolic Computation 8, 4 (1995), 357--397. Google Scholar
Digital Library
- Torbjörn Ekman and Görel Hedin. 2007. The JastAdd extensible java compiler. In Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems and Applications. 1--18. Google Scholar
Digital Library
- Erik Ernst. 2001. Family polymorphism. In Proceedings of the European Conference on Object-Oriented Programming. Springer, 303--326. Google Scholar
Digital Library
- Kathleen Fisher and John C. Mitchell. 1995. The Development of Type Systems for Object-Oriented Languages. Theory and Practice of Object Systems 1, 3 (Fall 1995), 189--220. Google Scholar
Digital Library
- John Foster. 2001. Rupiah: Towards an Expressive Static Type System for Java. Williams College Senior Honors Thesis. Williams College.Google Scholar
- James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. 2005. The Java Language Specification (3rd. ed.). Addison-Wesley Longman.Google Scholar
- Görel Hedin. 2000. Reference attributed grammars. Informatica 24 (2000), 301--317.Google Scholar
- Görel Hedin, Emma Söderberg, Niklas Fors, and Jesper Öqvist. 2011. JastAdd. Retrieved from http://jastadd.org.Google Scholar
- Martin Hofmann and Benjamin Pierce. 1995. A unifying type-theoretic framework for objects. Journal of Functional Programming 5, 4 (1995), 593--635.Google Scholar
Cross Ref
- Atsushi Igarashi, Benjamin C. Pierce, and Philip Wadler. 2001. Featherweight java: A minimal core calculus for java and GJ. ACM Transactions on Programming Languages and Systems 23, 3 (May 2001), 396--450. Google Scholar
Digital Library
- Atsushi Igarashi and Mirko Viroli. 2006. Variant parametric types: A flexible subtyping scheme for generics. ACM Transactions on Programming Languages and Systems 28, 5 (Sept. 2006), 795--847. Google Scholar
Digital Library
- Samuel N. Kamin. 1988. Inheritance in Smalltalk-80: A denotational definition. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 80--87. Google Scholar
Digital Library
- Samuel N. Kamin and Uday S. Reddy. 1994. Two semantic models of object-oriented languages. In Theoretical Aspects of Object-Oriented Programming. MIT Press, 463--495. Google Scholar
Digital Library
- Wilf LaLonde and John Pugh. 1991. Subclassing ≠ subtyping ≠ is-a. Journal of Object Oriented Programming 3, 5 (1991), 57--62. Google Scholar
Digital Library
- Hongki Lee, Sooncheol Won, Joonho Jin, Junhee Cho, and Sukyoung Ryu. 2012. SAFE: Formal specification and implementation of a scalable analysis framework for ECMAScript. In Proceedings of the 2012 International Workshop on Foundations of Object-Oriented Languages.Google Scholar
- Tim Lindholm, Frank Yellin, Gilad Bracha, and Alex Buckley. 2012. The Java™ Virtual Machine Specification, Java SE 7 Edition. Oracle America, Inc. Google Scholar
Digital Library
- Barbara Liskov. 1987. Keynote address—Data abstraction and hierarchy. In Conference on Object-Oriented Programming Systems, Languages, and Applications. Google Scholar
Digital Library
- Julian Mackay, Hannes Mehnert, Alex Potanin, Lindsay Groves, and Nicholas Cameron. 2012. Encoding featherweight java with assignment and immutability using the Coq proof assistant. In Proceedings of the 14th Workshop on Formal Techniques for Java-like Programs. 11--19. Google Scholar
Digital Library
- Karl Mazurak and Steve Zdancewic. 2006. Type inference for java 5: Wildcards, f-bounds, and undecidability. In Proceedings of the 8th Workshop on Formal Techniques for Java-like Programs.Google Scholar
- Bertrand Meyer. 1988. Object-Oriented Software Construction. Prentice-Hall. Google Scholar
Digital Library
- Microsoft. 2010. C♯ Language Specification Version 4.0. Retrieved from http://msdn.microsoft.com/vcsharp/.Google Scholar
- John C. Mitchell. 1990. Toward a typed foundation for method specialization and inheritance. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 109--124. Google Scholar
Digital Library
- Steven S. Muchnick. 1997. Advanced Compiler Design and Implementation. Morgan Kaufmann. Google Scholar
Digital Library
- Hyunik Na. 2013. Languages with ThisType. Retrieved from http://plrg.kaist.ac.kr/research/software.Google Scholar
- Hyunik Na and Sukyoung Ryu. 2013. ThisJava: An extension of java with exact types. In Proceedings of the 11th Asian Symposium on Programming Languages and Systems. Vol. 8301. 233--240. Google Scholar
Digital Library
- Hyunik Na and Sukyoung Ryu. 2014. A new formalization of subtyping to match subclasses to subtypes. In Proceedings of the 12th International Symposium on Functional and Logic Programming. 238--252.Google Scholar
Cross Ref
- Hyunik Na, Sukyoung Ryu, and Kwangmoo Choe. 2012. Exact type parameterization and ThisType support. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation. 13--24. Google Scholar
Digital Library
- Nathaniel Nystrom, Stephen Chong, and Andrew C. Myers. 2004. Scalable extensibility via nested inheritance. In Proceedings of the 19th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications. 99--115. Google Scholar
Digital Library
- Martin Odersky, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, Matthias Zenger, and et al. 2013. Scala Reflection Library 2.11.2 -- scala.reflect.api.Types.ThisType. (2013). http://www.scala-lang.org/api/2.11.2/scala-reflect/index.html#scala.reflect.api.Types$ThisType.Google Scholar
- Martin Odersky, Lex Spoon, and Bill Venners. 2008. Programming in Scala. Artima Inc., Chapter 28.Google Scholar
- Oracle. 2012. OpenJDK 6 source. Retrieved from http://download.java.net/openjdk/jdk6/.Google Scholar
- Benjamin C. Pierce. 2002. Types and Programming Languages. The MIT Press. Google Scholar
Digital Library
- Benjamin C. Pierce and David N. Turner. 1994. Simple type-theoretic foundations for object-oriented programming. Journal of Functional Programming 4, 2 (1994), 207--247.Google Scholar
Cross Ref
- [email protected]. 2012. SAFE: Scalable Analysis Framework for ECMAScript. Retrieved from http://safe.kaist.ac.kr.Google Scholar
- Uday Reddy. 1988. Objects as closures: Abstract semantics of object-oriented languages. In Proceedings of the 1988 ACM Conference on LISP and Functional Programming. 289--297. Google Scholar
Digital Library
- Chieri Saito and Atsushi Igarashi. 2009. Matching ThisType to subtyping. In Proceedings of the 24th Annual ACM Symposium on Applied Computing. 1851--1858. Google Scholar
Digital Library
- Chieri Saito, Atsushi Igarashi, and Mirko Viroli. 2008. Lightweight family polymorphism. Journal of Functional Programming 18, 3 (2008), 285--331. Google Scholar
Digital Library
- Kresten Krab Thorup and Mads Torgersen. 1999. Unifying genericity—Combining the benefits of virtual types and parameterized classes. In Proceedings of the 13th European Conference on Object-Oriented Programming. 186--204. Google Scholar
Digital Library
- Mads Torgersen, Erik Ernst, and Christian Plesner Hansen. 2005. Wild FJ. In Proceedings of the 12th International Workshop on Foundations of Object-Oriented Languages.Google Scholar
- Mads Torgersen, Christian Plesner Hansen, Erik Ernst, Peter von der Ahé, Gilad Bracha, and Neal Gafter. 2004. Adding wildcards to the Java programming language. In Proceedings of the 19th Annual ACM Symposium on Applied Computing. 1289--1296. Google Scholar
Digital Library
- Andrew K. Wright and Matthias Felleisen. 1992. A syntactic approach to type soundness. Information and Computation 115 (1992), 38--94. Google Scholar
Digital Library
- Yoav Zibin, Alex Potanin, Paley Li, Mahmood Ali, and Michael D. Ernst. 2010. Ownership and immutability in generic java. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications. 598--617. Google Scholar
Digital Library
Index Terms
ThisType for Object-Oriented Languages: From Theory to Practice
Recommendations
Exact type parameterization and ThisType support
TLDI '12: Proceedings of the 8th ACM SIGPLAN workshop on Types in language design and implementationWe propose language support for binary methods and generic factory methods using ThisType. We present three new language features: (1) exact type capture which relaxes the restriction of earlier static approaches to binary methods that the run-time type ...
Matching ThisType to subtyping
SAC '09: Proceedings of the 2009 ACM symposium on Applied ComputingThe notion of ThisType has been proposed to promote typesafe reuse of binary methods and recently extended to mutually recursive definitions. It is well-known, however, that ThisType does not match with subtyping well. In the current type systems, type ...
Matching MyType to subtyping
The notion of MyType has been proposed to promote type-safe reuse of binary methods and recently extended to mutually recursive definitions. It is well known, however, that MyType does not match with subtyping well. In current type systems, type safety ...






Comments