Abstract
Parametric polymorphism and inheritance are both important, extensively explored language mechanisms for providing code reuse and extensibility. But harmoniously integrating these apparently distinct mechanisms—and powerful recent forms of them, including type classes and family polymorphism—in a single language remains an elusive goal. In this paper, we show that a deep unification can be achieved by generalizing the semantics of interfaces and classes. The payoff is a significant increase in expressive power with little increase in programmer-visible complexity. Salient features of the new programming language include retroactive constraint modeling, underpinning both object-oriented programming and generic programming, and module-level inheritance with further-binding, allowing family polymorphism to be deployed at large scale. The resulting mechanism is syntactically light, and the more advanced features are transparent to the novice programmer. We describe the design of a programming language that incorporates this mechanism; using a core calculus, we show that the type system is sound. We demonstrate that this language is highly expressive by illustrating how to use it to implement highly extensible software and by showing that it can not only concisely model state-of-the-art features for code reuse, but also go beyond them.
Supplemental Material
Available for Download
- M. Abadi and L. Cardelli. On subtyping and matching. ACM Trans. on Programming Languages and Systems, 18(4), July 1996. Google Scholar
Digital Library
- M. Abadi, L. Cardelli, and R. Viswanathan. An interpretation of objects and object types. In 23 rd ACM Symp. on Principles of Programming Languages (POPL), 1996. Google Scholar
Digital Library
- A. V. Aho, J. E. Hopcroft, and J. Ullman. Data Structures and Algorithms. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1st edition, 1983.Google Scholar
Digital Library
- A. V. Aho, M. S. Lam, R. Sethi, and J. D. Ullman. Compilers: Principles, Techniques, and Tools (2nd Edition). Addison-Wesley Longman Publishing Co., Inc., 2006.Google Scholar
Digital Library
- I. Aracic, V. Gasiunas, M. Mezini, and K. Ostermann. An overview of CaesarJ. In A. Rashid and M. Aksit, editors, Lecture Notes in Computer Science: Transactions on Aspect-Oriented Software Development I, pages 135–173. Springer-Verlag, 2006. Google Scholar
Cross Ref
- A. P. Black, K. B. Bruce, and R. J. Noble. The essence of inheritance. In A List of Successes That Can Change the World, volume 9600 of LNCS, pages 73–94. Springer, Mar. 2016.Google Scholar
- G. Bracha, P. von der Ahé, V. Bykov, Y. Kashai, W. Maddox, and E. Miranda. Modules as objects in Newspeak. In 24 th European Conf. on Object-Oriented Programming, 2010. Google Scholar
Cross Ref
- K. Bruce, L. Cardelli, and B. Pierce. Comparing object encodings. Information and Computation, 155(1):108–133, 1999. Google Scholar
Digital Library
- K. B. Bruce. A paradigmatic object-oriented programming language: Design, static typing and semantics. Journal of Functional Programming, 4(2):127–206, 1994. Google Scholar
Cross Ref
- K. B. Bruce and J. N. Foster. LOOJ: Weaving LOOM into Java. In European Conf. on Object-Oriented Programming, 2004. Google Scholar
Cross Ref
- K. B. Bruce, A. Fiech, and L. Petersen. Subtyping is not a good “match” for object-oriented languages. In Proceedings of 11th European Conference on Object-Oriented Programming (ECOOP’97), number 1241 in Lecture Notes in Computer Science, pages 104–127, June 1997. Google Scholar
Cross Ref
- K. B. Bruce, M. Odersky, and P. Wadler. A statically safe alternative to virtual types. In 12 th European Conf. on Object-Oriented Programming, number 1445 in Lecture Notes in Computer Science, pages 523–549, July 1998. Google Scholar
Cross Ref
- K. B. Bruce, A. Schuett, R. van Gent, and A. Fiech. PolyTOIL: A type-safe polymorphic object-oriented language. ACM Trans. on Programming Languages and Systems, 25(2):225–290, Mar. 2003. Google Scholar
Digital Library
- P. Canning, W. Cook, W. Hill, J. Mitchell, and W. Olthoff. F-bounded polymorphism for object-oriented programming. In Conf. on Functional Programming Languages and Computer Architecture, pages 273–280, 1989.Google Scholar
Digital Library
- L. Cardelli. A semantics of multiple inheritance. Information and Computation, 76(2–3):138–164, 1988. Also in Readings in Object-Oriented Database Systems, S. Zdonik and D. Maier, eds., Morgan Kaufmann, 1990.Google Scholar
Digital Library
- M. M. T. Chakravarty, G. Keller, and S. P. Jones. Associated type synonyms. In 10 th ACM SIGPLAN Int’l Conf. on Functional Programming, 2005a. Google Scholar
Digital Library
- M. M. T. Chakravarty, G. Keller, S. P. Jones, and S. Marlow. Associated types with class. In 32 nd ACM Symp. on Principles of Programming Languages (POPL), 2005b. Google Scholar
Digital Library
- C. Chambers. Object-oriented multi-methods in Cecil. In O. L. Madsen, editor, 20 th European Conf. on Object-Oriented Programming, volume 615, pages 33–56, 1992. Google Scholar
Cross Ref
- D. Clarke, S. Drossopoulou, J. Noble, and T. Wrigstad. Tribe: A simple virtual class calculus. In AOSD ’07: Proceedings of the 6th International Conference on Aspect-Oriented Software Development, pages 121–134, 2007. Google Scholar
Digital Library
- W. Cook and J. Palsberg. A denotational semantics of inheritance and its correctness. In 4 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 1989.Google Scholar
- W. R. Cook. On understanding data abstraction, revisited. In 24 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 557–572, 2009.Google Scholar
- W. R. Cook, W. L. Hill, and P. S. Canning. Inheritance is not subtyping. In Conference Record of the Seventeenth Annual ACM Symposium on Principles of Programming Languages, San Francisco, California, pages 125–135, Jan. 1990. Also STL-89-17, Software Technology Laboratory, Hewlett-Packard Laboratories, Palo Alto, CA, July 1989.Google Scholar
Digital Library
- D. Devriese and F. Piessens. On the bright side of type classes: Instance arguments in Agda. In 16 th ACM SIGPLAN Int’l Conf. on Functional Programming, 2011.Google Scholar
- D. Dreyer, R. Harper, M. M. T. Chakravarty, and G. Keller. Modular type classes. In 34 th ACM Symp. on Principles of Programming Languages (POPL), 2007. Google Scholar
Digital Library
- E. Ernst. gbeta—a Language with Virtual Attributes, Block Structure, and Propagating, Dynamic Inheritance. PhD thesis, Department of Computer Science, University of Aarhus, Aarhus, Denmark, 1999.Google Scholar
- E. Ernst. Family polymorphism. In 15 th European Conf. on Object-Oriented Programming, LNCS 2072, pages 303–326, 2001. Google Scholar
Cross Ref
- E. Ernst, K. Ostermann, and W. R. Cook. A virtual class calculus. In 33 rd ACM Symp. on Principles of Programming Languages (POPL), pages 270–282, Jan. 2006. Google Scholar
Digital Library
- J. Gosling, B. Joy, G. Steele, and G. Bracha. The Java Language Specification. Addison Wesley, 3nd edition, 2005.Google Scholar
Digital Library
- B. Greenman, F. Muehlboeck, and R. Tate. Getting F-bounded polymorphism into shape. In 35 th ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 89–99, 2014.Google Scholar
- R. Grigore. Java generics are Turing complete. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google Scholar
Digital Library
- C. Gunter and J. C. Mitchell, editors. Theoretical aspects of object-oriented programming. MIT Press, 1994.Google Scholar
Digital Library
- A. Igarashi and B. Pierce. Foundations for virtual types. In Thirteenth European Conference on Object-Oriented Programming (ECOOP’99), number 1628 in Lecture Notes in Computer Science, pages 161–185, June 1999. Google Scholar
Cross Ref
- A. Igarashi and M. Viroli. Variant path types for scalable extensibility. In 22 nd ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 113–132, 2007.Google Scholar
- A. Igarashi, B. Pierce, and P. Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM Trans. on Programming Languages and Systems, 23(3):396–450, 2001. Google Scholar
Digital Library
- J. Järvi, J. Willcock, and A. Lumsdaine. Associated types and constraint propagation for mainstream object-oriented generics. In 20 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2005.Google Scholar
- P. Jolly, S. Drossopoulou, C. Anderson, and K. Ostermann. Simple dependent types: Concord. In ECOOP Workshop on Formal Techniques for Java Programs (FTfJP), June 2004.Google Scholar
- S. P. Jones, M. Jones, and E. Meijer. Type classes: an exploration of the design space. In Haskell Workshop, 1997.Google Scholar
- B. Liskov, A. Snyder, R. Atkinson, and J. C. Schaffert. Abstraction mechanisms in CLU. Comm. of the ACM, 20(8):564–576, Aug. 1977. Also in S. Zdonik and D. Maier, eds., Readings in Object-Oriented Database Systems. Google Scholar
Digital Library
- B. Liskov, R. Atkinson, T. Bloom, J. E. Moss, J. C. Schaffert, R. Scheifler, and A. Snyder. CLU Reference Manual. Springer-Verlag, 1984. Also published as Lecture Notes in Computer Science 114, G. Goos and J. Hartmanis, Eds., Springer-Verlag, 1981.Google Scholar
Digital Library
- D. MacQueen. Modules for Standard ML. In 1984 ACM Symposium on Lisp and Functional Programming, pages 198–204, Aug. 1984. Google Scholar
Digital Library
- O. L. Madsen. Semantic analysis of virtual classes and nested classes. In 14 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 114–131, Nov. 1999.Google Scholar
- O. L. Madsen and B. Møller-Pedersen. Virtual classes: A powerful mechanism for object-oriented programming. In 4 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 397–406, Oct. 1989.Google Scholar
- O. L. Madsen, B. Møller-Pedersen, and K. Nygaard. Object Oriented Programming in the BETA Programming Language. Addison-Wesley, June 1993.Google Scholar
Digital Library
- R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978. Google Scholar
Cross Ref
- A. Moors, F. Piessens, and M. Odersky. Generics of a higher kind. In 23 rd ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), 2008.Google Scholar
- F. Nielson, H. R. Nielson, and C. Hankin. Principles of Program Analysis. Springer-Verlag New York, Inc., 1999. Google Scholar
Cross Ref
- N. Nystrom, S. Chong, and A. C. Myers. Scalable extensibility via nested inheritance. In 19 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 99–115, Oct. 2004.Google Scholar
- N. Nystrom, X. Qi, and A. C. Myers. J&: Nested intersection for scalable software composition. In 21 st ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 21–36, Oct. 2006.Google Scholar
- M. Odersky and M. Zenger. Scalable component abstractions. In 20 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 41–57, Oct. 2005.Google Scholar
- M. Odersky, V. Cremet, C. Röckl, and M. Zenger. A nominal theory of objects with dependent types. In Proceedings of 17th European Conference on Object-Oriented Programming (ECOOP 2003), number 2743 in Lecture Notes in Computer Science, pages 201–224, July 2003. Google Scholar
Cross Ref
- B. C. Oliveira, A. Moors, and M. Odersky. Type classes as objects and implicits. In 25 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 341–360, 2010.Google Scholar
- K. Ostermann. Dynamically composable collaborations with delegation layers. In 16 th European Conf. on Object-Oriented Programming, volume 2374 of Lecture Notes in Computer Science, pages 89–110, 2002. Google Scholar
Cross Ref
- L. Palmer. Haskell antipattern: Existential typeclass. https://lukepalmer.wordpress.com/2010/01/24/ haskell- antipattern- existential- typeclass , 2010.Google Scholar
- S. Peyton Jones. Classes, Jim, but not as we know them—type classes in Haskell: What, why, and whither. In 23 rd European Conf. on Object-Oriented Programming, 2009.Google Scholar
- B. Pierce and M. Steffen. Higher-order subtyping. Theoretical Computer Science, 176(1), 1997. Google Scholar
Digital Library
- X. Qi and A. C. Myers. Homogeneous family sharing. In 25 th ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 520–538, Oct. 2010.Google Scholar
- J. C. Reynolds. User-defined types and procedural data structures as complementary approaches to data abstraction. In S. A. Schuman, editor, New Directions in Algorithmic Languages, pages 157–168. Institut de Recherche d’Informatique et d’Automatique, Le Chesnay, France, 1975. Reprinted in [ Gunter and Mitchell 1994 ], pages 13–23.Google Scholar
- Rust 2014. Rust programming language. http://doc.rust-lang.org/0.11.0/rust.html, 2014.Google Scholar
- S. Ryu. ThisType for object-oriented languages: From theory to practice. ACM Trans. on Programming Languages and Systems, 38(3), Apr. 2016. Google Scholar
Digital Library
- J. G. Siek and A. Lumsdaine. A language for generic programming in the large. Science of Computer Programming, 76(5): 423–465, 2011. Google Scholar
Digital Library
- Y. Smaragdakis and D. Batory. Mixin layers: An object-oriented implementation technique for refinements and collaborationbased designs. ACM Transactions on Software Engineering and Methodology, 11(2):215–255, Apr. 2002. Google Scholar
Digital Library
- B. Stroustrup. The C++ Programming Language. Addison-Wesley, 1987.Google Scholar
- B. Stroustrup. The C++0x “remove concepts” decision. Dr. Dobbs, July 2009.Google Scholar
- Swift 2014. Swift programming language. https://developer.apple.com/swift/resources , 2014.Google Scholar
- K. K. Thorup. Genericity in Java with virtual types. In European Conf. on Object-Oriented Programming, number 1241 in Lecture Notes in Computer Science, pages 444–471, 1997. Google Scholar
Cross Ref
- M. Torgersen. Virtual types are statically safe. In 5th Workshop on Foundations of Object-Oriented Languages (FOOL), Jan. 1998.Google Scholar
- M. Torgersen, C. P. Hansen, E. Ernst, P. von der Ahé, G. Bracha, and N. Gafter. Adding wildcards to the Java programming language. In 2004 ACM Symposium on Applied Computing, SAC ’04, pages 1289–1296, 2004. Google Scholar
Digital Library
- P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In 16 th ACM Symp. on Principles of Programming Languages (POPL), 1989. Google Scholar
Digital Library
- P. Wadler et al. The expression problem, Dec. 1998. Discussion on Java-Genericity mailing list.Google Scholar
- A. Warth, M. Stanojević, and T. Millstein. Statically scoped object adaptation with expanders. In 21 st ACM SIGPLAN Conf. on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), Oct. 2006.Google Scholar
- S. Wehr and P. Thiemann. JavaGI: The interaction of type classes with interfaces and inheritance. ACM Trans. on Programming Languages and Systems, 33(4):12:1–12:83, July 2011.Google Scholar
Digital Library
- M. Weiel, I. Maier, S. Erdweg, M. Eichberg, and M. Mezini. Towards virtual traits in Scala. In Scala ’14, pages 67–75, July 2014. Google Scholar
Digital Library
- A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Technical Report TR91-160, Rice University, 1992.Google Scholar
- Y. Zhang, M. C. Loring, G. Salvaneschi, B. Liskov, and A. C. Myers. Genus: Making generics object-oriented, expressive, and lightweight. Technical Report 1813–39910, Cornell University Computing and Information Science, June 2015a.Google Scholar
- Y. Zhang, M. C. Loring, G. Salvaneschi, B. Liskov, and A. C. Myers. Lightweight, flexible object-oriented generics. In 36 th ACM SIGPLAN Conf. on Programming Language Design and Implementation (PLDI), pages 436–445, June 2015b.Google Scholar
Index Terms
Familia: unifying interfaces, type classes, and family polymorphism
Recommendations
Type families with class, type classes with family
Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on HaskellType classes and type families are key ingredients in Haskell programming. Type classes were introduced to deal with ad-hoc polymorphism, although with the introduction of functional dependencies, their use expanded to type-level programming. Type ...
Type families with class, type classes with family
Haskell '15Type classes and type families are key ingredients in Haskell programming. Type classes were introduced to deal with ad-hoc polymorphism, although with the introduction of functional dependencies, their use expanded to type-level programming. Type ...
Polymorphic variants in Haskell
Haskell '06: Proceedings of the 2006 ACM SIGPLAN workshop on HaskellIn languages that support polymorphic variants, a single variant value can be passed to many contexts that accept different sets of constructors. Polymorphic variants can be used in order to introduce extensible algebraic datatypes into functional ...






Comments