skip to main content
research-article
Open Access
Artifacts Available

Familia: unifying interfaces, type classes, and family polymorphism

Published:12 October 2017Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

References

  1. M. Abadi and L. Cardelli. On subtyping and matching. ACM Trans. on Programming Languages and Systems, 18(4), July 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarCross RefCross Ref
  6. 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 ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarCross RefCross Ref
  8. K. Bruce, L. Cardelli, and B. Pierce. Comparing object encodings. Information and Computation, 155(1):108–133, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. K. B. Bruce. A paradigmatic object-oriented programming language: Design, static typing and semantics. Journal of Functional Programming, 4(2):127–206, 1994. Google ScholarGoogle ScholarCross RefCross Ref
  10. K. B. Bruce and J. N. Foster. LOOJ: Weaving LOOM into Java. In European Conf. on Object-Oriented Programming, 2004. Google ScholarGoogle ScholarCross RefCross Ref
  11. 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 ScholarGoogle ScholarCross RefCross Ref
  12. 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 ScholarGoogle ScholarCross RefCross Ref
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarCross RefCross Ref
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle Scholar
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle Scholar
  26. E. Ernst. Family polymorphism. In 15 th European Conf. on Object-Oriented Programming, LNCS 2072, pages 303–326, 2001. Google ScholarGoogle ScholarCross RefCross Ref
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. J. Gosling, B. Joy, G. Steele, and G. Bracha. The Java Language Specification. Addison Wesley, 3nd edition, 2005.Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle Scholar
  30. R. Grigore. Java generics are Turing complete. In 44 th ACM Symp. on Principles of Programming Languages (POPL), 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. C. Gunter and J. C. Mitchell, editors. Theoretical aspects of object-oriented programming. MIT Press, 1994.Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. 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 ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle Scholar
  36. 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 ScholarGoogle Scholar
  37. S. P. Jones, M. Jones, and E. Meijer. Type classes: an exploration of the design space. In Haskell Workshop, 1997.Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. D. MacQueen. Modules for Standard ML. In 1984 ACM Symposium on Lisp and Functional Programming, pages 198–204, Aug. 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle Scholar
  42. 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 ScholarGoogle Scholar
  43. O. L. Madsen, B. Møller-Pedersen, and K. Nygaard. Object Oriented Programming in the BETA Programming Language. Addison-Wesley, June 1993.Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978. Google ScholarGoogle ScholarCross RefCross Ref
  45. 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 ScholarGoogle Scholar
  46. F. Nielson, H. R. Nielson, and C. Hankin. Principles of Program Analysis. Springer-Verlag New York, Inc., 1999. Google ScholarGoogle ScholarCross RefCross Ref
  47. 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 ScholarGoogle Scholar
  48. 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 ScholarGoogle Scholar
  49. 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 ScholarGoogle Scholar
  50. 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 ScholarGoogle ScholarCross RefCross Ref
  51. 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 ScholarGoogle Scholar
  52. 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 ScholarGoogle ScholarCross RefCross Ref
  53. L. Palmer. Haskell antipattern: Existential typeclass. https://lukepalmer.wordpress.com/2010/01/24/ haskell- antipattern- existential- typeclass , 2010.Google ScholarGoogle Scholar
  54. 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 ScholarGoogle Scholar
  55. B. Pierce and M. Steffen. Higher-order subtyping. Theoretical Computer Science, 176(1), 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. 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 ScholarGoogle Scholar
  57. 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 ScholarGoogle Scholar
  58. Rust 2014. Rust programming language. http://doc.rust-lang.org/0.11.0/rust.html, 2014.Google ScholarGoogle Scholar
  59. S. Ryu. ThisType for object-oriented languages: From theory to practice. ACM Trans. on Programming Languages and Systems, 38(3), Apr. 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. J. G. Siek and A. Lumsdaine. A language for generic programming in the large. Science of Computer Programming, 76(5): 423–465, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  62. B. Stroustrup. The C++ Programming Language. Addison-Wesley, 1987.Google ScholarGoogle Scholar
  63. B. Stroustrup. The C++0x “remove concepts” decision. Dr. Dobbs, July 2009.Google ScholarGoogle Scholar
  64. Swift 2014. Swift programming language. https://developer.apple.com/swift/resources , 2014.Google ScholarGoogle Scholar
  65. 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 ScholarGoogle ScholarCross RefCross Ref
  66. M. Torgersen. Virtual types are statically safe. In 5th Workshop on Foundations of Object-Oriented Languages (FOOL), Jan. 1998.Google ScholarGoogle Scholar
  67. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  68. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  69. P. Wadler et al. The expression problem, Dec. 1998. Discussion on Java-Genericity mailing list.Google ScholarGoogle Scholar
  70. 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 ScholarGoogle Scholar
  71. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  72. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  73. A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Technical Report TR91-160, Rice University, 1992.Google ScholarGoogle Scholar
  74. 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 ScholarGoogle Scholar
  75. 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 ScholarGoogle Scholar

Index Terms

  1. Familia: unifying interfaces, type classes, and family polymorphism

                        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!