ABSTRACT
Support for object-oriented programming has become an integral part of mainstream languages, and more recently generic programming has gained widespread acceptance as well. A natural question is how these two paradigms, and their underlying language mechanisms, should interact. One particular design option, that of using subtyping to constrain the type parameters of generic functions, has been chosen in the generics of Java and those planned for a future revision of C#.Certain shortcomings have previously been identified in using subtyping for constraining parametric polymorphism in the context of generic programming.To address these, we propose extending object-oriented interfaces and subtyping to include associated types and constraint propagation.Associated types are type members of interfaces and classes. Constraint propagation allows certain constraints on type parameters to be inferred from other constraints on those parameters and their use in base class type expressions.The paper demonstrates these extensions in the context of C# (with generics), describes a translation of the extended features to C#, and presents a formalism proving their safety. The formalism is applicable to other mainstream object-oriented languages supporting F-bounded polymorphism, such as Java.
- Stepanov, A., Lee, M.: The Standard Template Library. Technical Report HPL-94-34(R.1), Hewlett-Packard Laboratories (1994) http://www.hpl.hp.com/techreports.]]Google Scholar
- Stepanov, A.: The Standard Template Library --- how do you build an algorithm that is both generic and efficient? Byte Magazine 20 (1995)]]Google Scholar
- An, P., Jula, A., Rus, S., Saunders, S., Smith, T., Tanase, G., Thomas, N., Amato, N., Rauchwerger, L.: STAPL: An adaptive, generic parallel C++ library. In: Languages and Compilers for Parallel Computing. Volume 2624 of Lecture Notes in Computer Science. Springer (2001) 193--208]]Google Scholar
- Siek, J., Lee, L.Q., Lumsdaine, A.: The Boost Graph Library: User Guide and Reference Manual. Addison-Wesley (2002)]] Google ScholarDigital Library
- Siek, J., Lumsdaine, A.: A modern framework for portable high performance numerical linear algebra. In: Modern Software Tools for Scientific Computing. Birkhäuser (1999)]]Google Scholar
- Pitt, W.R., Williams, M.A., Steven, M., Sweeney, B., Bleasby, A.J., Moss, D.S.: The Bioinformatics Template Library--generic components for biocomputing. Bioinformatics 17 (2001) 729--737]]Google ScholarCross Ref
- Microsoft Corporation: C# Version 2.0 Specification, March 2005 Draft. (2005) http://msdn.microsoft.com/vcsharp/programming/language.]]Google Scholar
- Garcia, R., Järvi, J., Lumsdaine, A., Siek, J., Willcock, J.: A comparative study of language support for generic programming. In: OOPSLA '03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applications, New York, NY, USA, ACM Press (2003) 115--134]] Google ScholarDigital Library
- Madsen, O.L., Moller-Pedersen, B.: Virtual classes: a powerful mechanism in object-oriented programming. In: OOPSLA '89: Conference proceedings on Object-oriented programming systems, languages and applications, ACM Press (1989) 397--406]] Google ScholarDigital Library
- Thorup, K.K.: Genericity in Java with virtual types. In: ECOOP '97. Volume 1241 of Lecture Notes in Computer Science. (1997) 444--471]]Google Scholar
- Canning, P., Cook, W., Hill, W., Olthoff, W., Mitchell, J.C.: F-bounded polymorphism for object-oriented programming. In: FPCA '89: Proceedings of the fourth international conference on Functional programming languages and computer architecture, New York, NY, USA, ACM Press (1989) 273--280]] Google ScholarDigital Library
- Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst. 23 (2001) 396--450]] Google ScholarDigital Library
- Kennedy, A., Syme, D.: Transposing F to C#: Expressivity of polymorphism in an object-oriented language. Concurrency and Computation: Practice and Experience 16 (2004) 707--733]] Google ScholarDigital Library
- Jazayeri, M., Loos, R., Musser, D., Stepanov, A.: Generic Programming. In: Report of the Dagstuhl Seminar on Generic Programming, Schloss Dagstuhl, Germany (1998)]] Google ScholarDigital Library
- Kapur, D., Musser, D.: Tecton: a framework for specifying and verifying generic system components. Technical Report RPI--92--20, Department of Computer Science, Rensselaer Polytechnic Institute, Troy, New York 12180 (1992)]]Google Scholar
- Austern, M.H.: Generic Programming and the STL. Professional computing series. Addison-Wesley (1999)]]Google Scholar
- Silicon Graphics, Inc.: SGI Implementation of the Standard Template Library. (2004) http://www.sgi.com/tech/stl/.]]Google Scholar
- International Organization for Standardization: ISO/IEC 14882:1998: Programming languages --- C++, Geneva, Switzerland (1998)]]Google Scholar
- Bruce, K.B., Fiech, A., Petersen, L.: Subtyping is not a good "match" for object-oriented languages. In: ECOOP '97. Volume 1241 of Lecture Notes in Computer Science., Springer-Verlag (1997) 104--127]]Google Scholar
- Thorup, K.K., Torgersen, M.: Unifying genericity --- combining the benefits of virtual types and parameterized classes. In: ECOOP '99. Volume 1628 of Lecture Notes in Computer Science., Springer-Verlag (1999) 186--204]] Google ScholarDigital Library
- Nystrom, N., Chong, S., Myers, A.C.: Scalable extensibility via nested inheritance. In: OOPSLA '04: Proceedings of the 19th annual ACM SIGPLAN Conference on Object-oriented programming, systems, languages, and applications, ACM Press (2004) 99--115]] Google ScholarDigital Library
- Torgersen, M.: Virtual types are statically safe. In: FOOL 5: Workshop on Foundations of Object-Oriented Languages. (1998) http://pauillac.inria.fr/~remy/fool/.]]Google Scholar
- Bruce, K.B., Cardelli, L., Castagna, G., Eifrig, J., Smith, S.F., Trifonov, V., Leavens, G.T., Pierce, B.C.: On binary methods. Theory and Practice of Object Systems 1 (1995) 221--242]] Google ScholarDigital Library
- Bruce, K.B., Odersky, M., Wadler, P.: A statically safe alternative to virtual types. In: ECOOP '98. Volume 1445. (1998) 523--549]] Google ScholarDigital Library
- Bruce, K.B., Vanderwaart, J.C.: Semantics-driven language design: Statically type-safe virtual types in object-oriented languages. In: Mathematical Foundations of Programming Semantics. Volume 20 of Electronic Notes in Theoretical Computer Science. (2000)]]Google Scholar
- Ernst, E.: Family polymorphism. In: ECOOP '01. Volume 2072 of Lecture Notes in Computer Science., Springer (2001) 303--326]] Google ScholarDigital Library
- Odersky, M., Cremet, V., Röckl, C., Zenger, M.: A nominal theory of objects with dependent types. In: ECOOP '03. Volume 2743 of Lecture Notes in Computer Science., Springer-Verlag (2003) 201--224]]Google Scholar
- Odersky, M., Altherr, P., Cremet, V., Emir, B., et al.: The Scala Language Specification. Programming Methods Laboratory, EPFL. Version 1.0 edn. (2005) http://scala.epfl.ch/docu/files/ScalaReference.pdf.]]Google Scholar
- Odersky, M., Zenger, C.: Nested types. In: FOOL 8: Workshop on Foundations of Object-Oriented Languages. (2001)]]Google Scholar
- Myers, N.: A new and useful technique: "traits". C++ Report 7 (1995) 32--35]]Google Scholar
- Milner, R., Tofte, M., Harper, R.: The Definition of Standard ML. MIT Press (1990)]] Google ScholarDigital Library
- Jones, M.P.: Type classes with functional dependencies. In: ESOP '00: Proceedings of the 9th European Symposium on Programming Languages and Systems. Volume 1782 of Lecture Notes in Computer Science., New York, NY, Springer-Verlag (2000) 230--244]] Google ScholarDigital Library
- Chakravarty, M.M.T., Keller, G., Peyton Jones, S., Marlow, S.: Associated types with class. In: POPL '05: Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, New York, NY, USA, ACM Press (2005) 1--13]] Google ScholarDigital Library
- Chakravarty, M.M.T., Keller, G., Peyton Jones, S.: Associated type synonyms. In: Proceedings of the International Conference on Functional Programming (ICFP '05), New York, NY, USA, ACM Press (2005)]] Google ScholarDigital Library
- Chambers, C., the Cecil Group: The Cecil Language: Specification and Rationale, Version 3.1. University of Washington, Computer Science and Engineering. (2002) http://www.cs.washington.edu/research/projects/cecil/.]]Google Scholar
- Torgersen, M., Hansen, C.P., Ernst, E., von der Ahé, P., Bracha, G., Gafter, N.: Adding wildcards to the Java programming language. In: ACM Symposium on Applied computing, ACM Press (2004) 1289--1296]] Google ScholarDigital Library
- Torgersen, M., Ernst, E., Hansen, C.P.: Wild FJ. In: FOOL 12: Workshop on Foundations of Object-Oriented Languages. (2005)]]Google Scholar
- Wadler, P., Blott, S.: How to make ad-hoc polymorphism less ad-hoc. In: ACM Symposium on Principles of Programming Languages, ACM (1989) 60--76]] Google ScholarDigital Library
- http://research.cs.tamu.edu/jarvi/csharp (2005)]]Google Scholar
Index Terms
- Associated types and constraint propagation for mainstream object-oriented generics
Recommendations
Associated types and constraint propagation for mainstream object-oriented generics
Proceedings of the 20th annual ACM SIGPLAN conference on Object oriented programming systems languages and applicationsSupport for object-oriented programming has become an integral part of mainstream languages, and more recently generic programming has gained widespread acceptance as well. A natural question is how these two paradigms, and their underlying language ...
A comparative study of language support for generic programming
OOPSLA '03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applicationsMany modern programming languages support basic generic programming, sufficient to implement type-safe polymorphic containers. Some languages have moved beyond this basic support to a broader, more powerful interpretation of generic programming, and ...
Generalized algebraic data types and object-oriented programming
OOPSLA '05: Proceedings of the 20th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applicationsGeneralized algebraic data types (GADTs) have received much attention recently in the functional programming community. They generalize the (type) parameterized algebraic datatypes (PADTs) of ML and Haskell by permitting value constructors to return ...
Comments