skip to main content
research-article
Free Access

ThisType for Object-Oriented Languages: From Theory to Practice

Published:08 April 2016Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Martin Abadi and Luca Cardelli. 1996b. A Theory of Objects. Springer-Verlag, New York, Inc. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Algred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. 2006. Compilers Principles, Techniques, & Tools (2nd. ed.). Addison Wesley. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. Ken Arnold, James Gosling, and David Holmes. 2005. The Java™ Programming Language (4th. ed.). Addison-Wesley.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarCross RefCross Ref
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Kim B. Bruce, Luca Cardelli, and Benjamin C. Pierce. 1997. Comparing object encodings. In Theoretical Aspects of Computer Software. Vol. 1281. 415--438. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle Scholar
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarCross RefCross Ref
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. Kim B. Bruce. 1997. Increasing Java’s Expressiveness with ThisType and Match-Bounded Polymorphism. Technical Report. Williams College.Google ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Luca Cardelli. 1984. A semantics of multiple inheritance. In Proceedings of the International Symposium on Semantics of Data Types. 51--67. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Luca Cardelli. 1986. Amber. In Proceedings of the 13th Spring School of the LITP on Combinators and Functional Programming Languages. 21--47. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. William R. Cook. 1989. A proposal for making Eiffel type-safe. Computer Journal 32, 4 (July 1989), 305--311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. Ecma. 2011. ECMAScript Language Specification. Edition 5.1. Retrieved from http://www.ecma-international.org/publications/standards/Ecma-262.htm.Google ScholarGoogle Scholar
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. Erik Ernst. 2001. Family polymorphism. In Proceedings of the European Conference on Object-Oriented Programming. Springer, 303--326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. John Foster. 2001. Rupiah: Towards an Expressive Static Type System for Java. Williams College Senior Honors Thesis. Williams College.Google ScholarGoogle Scholar
  30. James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. 2005. The Java Language Specification (3rd. ed.). Addison-Wesley Longman.Google ScholarGoogle Scholar
  31. Görel Hedin. 2000. Reference attributed grammars. Informatica 24 (2000), 301--317.Google ScholarGoogle Scholar
  32. Görel Hedin, Emma Söderberg, Niklas Fors, and Jesper Öqvist. 2011. JastAdd. Retrieved from http://jastadd.org.Google ScholarGoogle Scholar
  33. Martin Hofmann and Benjamin Pierce. 1995. A unifying type-theoretic framework for objects. Journal of Functional Programming 5, 4 (1995), 593--635.Google ScholarGoogle ScholarCross RefCross Ref
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. Wilf LaLonde and John Pugh. 1991. Subclassing ≠ subtyping ≠ is-a. Journal of Object Oriented Programming 3, 5 (1991), 57--62. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle Scholar
  40. Tim Lindholm, Frank Yellin, Gilad Bracha, and Alex Buckley. 2012. The Java™ Virtual Machine Specification, Java SE 7 Edition. Oracle America, Inc. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Barbara Liskov. 1987. Keynote address—Data abstraction and hierarchy. In Conference on Object-Oriented Programming Systems, Languages, and Applications. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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 ScholarGoogle Scholar
  44. Bertrand Meyer. 1988. Object-Oriented Software Construction. Prentice-Hall. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Microsoft. 2010. C♯ Language Specification Version 4.0. Retrieved from http://msdn.microsoft.com/vcsharp/.Google ScholarGoogle Scholar
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. Steven S. Muchnick. 1997. Advanced Compiler Design and Implementation. Morgan Kaufmann. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Hyunik Na. 2013. Languages with ThisType. Retrieved from http://plrg.kaist.ac.kr/research/software.Google ScholarGoogle Scholar
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarCross RefCross Ref
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. 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 ScholarGoogle Scholar
  54. Martin Odersky, Lex Spoon, and Bill Venners. 2008. Programming in Scala. Artima Inc., Chapter 28.Google ScholarGoogle Scholar
  55. Oracle. 2012. OpenJDK 6 source. Retrieved from http://download.java.net/openjdk/jdk6/.Google ScholarGoogle Scholar
  56. Benjamin C. Pierce. 2002. Types and Programming Languages. The MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. 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 ScholarGoogle ScholarCross RefCross Ref
  58. [email protected]. 2012. SAFE: Scalable Analysis Framework for ECMAScript. Retrieved from http://safe.kaist.ac.kr.Google ScholarGoogle Scholar
  59. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  60. Chieri Saito and Atsushi Igarashi. 2009. Matching ThisType to subtyping. In Proceedings of the 24th Annual ACM Symposium on Applied Computing. 1851--1858. Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. Chieri Saito, Atsushi Igarashi, and Mirko Viroli. 2008. Lightweight family polymorphism. Journal of Functional Programming 18, 3 (2008), 285--331. Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  63. 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 ScholarGoogle Scholar
  64. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  65. Andrew K. Wright and Matthias Felleisen. 1992. A syntactic approach to type soundness. Information and Computation 115 (1992), 38--94. Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. ThisType for Object-Oriented Languages: From Theory to Practice

      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

      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!