skip to main content
research-article

Lightweight, flexible object-oriented generics

Published:03 June 2015Publication History
Skip Abstract Section

Abstract

The support for generic programming in modern object-oriented programming languages is awkward and lacks desirable expressive power. We introduce an expressive genericity mechanism that adds expressive power and strengthens static checking, while remaining lightweight and simple in common use cases. Like type classes and concepts, the mechanism allows existing types to model type constraints retroactively. For expressive power, we expose models as named constructs that can be defined and selected explicitly to witness constraints; in common uses of genericity, however, types implicitly witness constraints without additional programmer effort. Models are integrated into the object-oriented style, with features like model generics, model-dependent types, model enrichment, model multimethods, constraint entailment, model inheritance, and existential quantification further extending expressive power in an object-oriented setting. We introduce the new genericity features and show that common generic programming idioms, including current generic libraries, can be expressed more precisely and concisely. The static semantics of the mechanism and a proof of a key decidability property can be found in an associated technical report.

References

  1. O. Agesen, S. N. Freund, and J. C. Mitchell. Adding type parameterization to the Java language. In Proc. 12th OOPSLA, pages 49–65, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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
  3. J. Aldrich. The power of interoperability: Why objects are inevitable. In Proc. ACM Int’l Symp. on New Ideas, New Paradigms, and Reflections on Programming & Software (Onward!), pages 101––116, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. M. H. Austern. Generic Programming and the STL: Using and Extending the C++ Standard Template Library. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. G. Bracha, M. Odersky, D. Stoutamire, and P. Wadler. Making the future safe for the past: Adding genericity to the Java programming language. In Proc. 13th OOPSLA, Oct. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. K. B. Bruce, M. Odersky, and P. Wadler. A statically safe alternative to virtual types. In Proc. 12th European Conf. on Object-Oriented Programming, number 1445 in Lecture Notes in Computer Science, pages 523–549, July 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. P. Canning, W. Cook, W. Hill, J. Mitchell, and W. Olthoff. F-bounded polymorphism for object-oriented programming. In Proc. Conf. on Functional Programming Languages and Computer Architecture, pages 273–280, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. R. Cartwright and G. L. Steele Jr. Compatible genericity with run-time types for the Java programming language. In Proc. 13th OOPSLA, pages 201–215, Oct. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. M. M. T. Chakravarty, G. Keller, S. Peyton-Jones, and S. Marlow. Associated types with class. In Proc. 32nd POPL, pages 1–13, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. C. Chambers. Object-oriented multi-methods in Cecil. In O. L. Madsen, editor, Proc. 20th European Conf. on Object-Oriented Programming, volume 615, pages 33–56, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Clifton, G. T. Leavens, C. Chambers, and T. Millstein. MultiJava: Modular open classes and symmetric multiple dispatch for Java. In Proc. 15th OOPSLA, pages 130–145, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. Day, R. Gruber, B. Liskov, and A. C. Myers. Subtypes vs. where clauses: Constraining parametric polymorphism. In Proc. 10th OOPSLA, pages 156–168, Oct. 1995. ACM SIGPLAN Notices 30(10). Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. D. Dreyer, R. Harper, M. M. T. Chakravarty, and G. Keller. Modular type classes. In Proc. 34th POPL, pages 63–70, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. B. Emir, A. Kennedy, C. Russo, and D. Yu. Variance and generalized constraints for C# generics. In Proc. 20th European Conf. on Object-Oriented Programming, pages 279–303, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. findbugs-release. Findbugs. http://findbugs.sourceforge.net/.Google ScholarGoogle Scholar
  16. R. Garcia, J. Jarvi, A. Lumsdaine, J. G. Siek, and J. Willcock. A comparative study of language support for generic programming. In Proc. 18th OOPSLA, pages 115–134, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Gosling, B. Joy, G. Steele, and G. Bracha. The Java Language Specification. Addison Wesley, 3rd edition, 2005. ISBN 0321246780. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. B. Greenman, F. Muehlboeck, and R. Tate. Getting F-bounded polymorphism into shape. In PLDI, pages 89–99, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. D. Gregor, J. Järvi, J. Siek, B. Stroustrup, G. Dos Reis, and A. Lumsdaine. Concepts: Linguistic support for generic programming in C++. In Proc. 21st OOPSLA, pages 291–310, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. A. Igarashi, B. Pierce, and P. Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM Transactions on Programming Languages and Systems, 23(3):396–450, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. A. Kennedy and D. Syme. Design and implementation of generics for the .NET Common Language Runtime. In PLDI, pages 1–12, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. B. Liskov, A. Snyder, R. Atkinson, and J. C. Schaffert. Abstraction mechanisms in CLU. Comm. of the ACM, 20(8):564–576, Aug. 1977. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Also in S. Zdonik and D. Maier, eds., Readings in Object-Oriented Database Systems.Google ScholarGoogle Scholar
  24. B. Liskov, R. Atkinson, T. Bloom, J. E. Moss, J. C. Schaffert, R. Scheifler, and A. Snyder. CLU Reference Manual. Springer-Verlag, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Also published as Lecture Notes in Computer Science 114, G. Goos and J. Hartmanis, Eds., Springer-Verlag, 1981.Google ScholarGoogle Scholar
  26. T. Millstein, M. Reay, and C. Chambers. Relaxed MultiJava: Balancing extensibility and modular typechecking. In Proc. 18th OOPSLA, pages 224–240, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. D. R. Musser, G. J. Derge, and A. Saini. The STL Tutorial and Reference Guide. Addison-Wesley, 2nd edition, 2001. ISBN 0-201- 37923-6. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. A. C. Myers, J. A. Bank, and B. Liskov. Parameterized types for Java. In Proc. 24th POPL, pages 132–145, Jan. 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. N. C. Myers. Traits: a new and useful template technique. C++ Report, 7(5), June 1995.Google ScholarGoogle Scholar
  30. N. Nystrom, M. R. Clarkson, and A. C. Myers. Polyglot: an extensible compiler framework for Java. In Proc. 12th Int’l Conf. on Compiler Construction (CC’03), volume 2622 of Lecture Notes in Computer Science, pages 138–152, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. M. Odersky. The Scala Language Specification. EPFL, 2014. Version 2.9.Google ScholarGoogle Scholar
  32. B. C. Oliveira, A. Moors, and M. Odersky. Type classes as objects and implicits. In Proc. 25th OOPSLA, pages 341–360, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. B. C. Oliveira, T. Schrijvers, W. Choi, W. Lee, and K. Yi. The implicit calculus: A new foundation for generic programming. In PLDI, pages 35–44, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. S. Peyton-Jones, M. Jones, and E. Meijer. Type classes: an exploration of the design space. In Haskell Workshop, 1997.Google ScholarGoogle Scholar
  35. Rust. Rust programming language. http://doc.rust-lang.org/1.0.0-beta, 2015.Google ScholarGoogle Scholar
  36. C. Schaffert, T. Cooper, B. Bullis, M. Kilian, and C. Wilpolt. An introduction to Trellis/Owl. In Proc. 1st OOPSLA, Sept. 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. J. G. Siek. The C++0x concepts effort. Arxiv preprint arXiv:1201.0027, Dec. 2011.Google ScholarGoogle Scholar
  38. J. G. Siek and A. Lumsdaine. Essential language support for generic programming. In PLDI, pages 73–84, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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
  40. M. Sulzmann, G. J. Duck, S. Peyton-Jones, and P. J. Stuckey. Understanding functional dependencies via constraint handling rules. J. Funct. Program., 17(1):83–129, Jan. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Swift. Swift programming language. https://developer.apple.com/swift/resources/, 2014.Google ScholarGoogle Scholar
  42. M. Torgersen, C. P. Hansen, E. Ernst, P. von der Ahé, G. Bracha, and N. Gafter. Adding wildcards to the Java programming language. In Proc. 2004 ACM Symposium on Applied Computing, SAC ’04, pages 1289–1296, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In Proc. 16th POPL, pages 60–76, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. A. Warth, M. Stanojevi´c, and T. Millstein. Statically scoped object adaptation with expanders. In Proc. 21st OOPSLA, Oct. 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. S. Wehr and P. Thiemann. JavaGI: The interaction of type classes with interfaces and inheritance. ACM Trans. Prog. Lang. Syst., 33(4):12:1– 12:83, July 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Y. Zhang, M. C. Loring, G. Salvaneschi, B. Liskov, and A. C. Myers. Genus: Making generics object-oriented, expressive, and lightweight. Technical Report http://hdl.handle.net/1813/39910, Cornell University, Apr. 2015.Google ScholarGoogle Scholar

Index Terms

  1. Lightweight, flexible object-oriented generics

        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

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 50, Issue 6
          PLDI '15
          June 2015
          630 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2813885
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            PLDI '15: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation
            June 2015
            630 pages
            ISBN:9781450334686
            DOI:10.1145/2737924

          Copyright © 2015 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 3 June 2015

          Check for updates

          Qualifiers

          • research-article

        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!