Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
article
Open access

Variant parametric types: A flexible subtyping scheme for generics

Published: 01 September 2006 Publication History

Abstract

We develop the mechanism of variant parametric types as a means to enhance synergy between parametric and inclusion polymorphism in object-oriented programming languages. Variant parametric types are used to control both the subtyping between different instantiations of one generic class and the accessibility of their fields and methods. On one hand, one parametric class can be used to derive covariant types, contravariant types, and bivariant types (generally called variant parametric types) by attaching a variance annotation to a type argument. On the other hand, the type system prohibits certain method/field accesses, according to variance annotations, when these accesses may otherwise make the program unsafe. By exploiting variant parametric types, a programmer can write generic code abstractions that work on a wide range of parametric types in a safe manner. For instance, a method that only reads the elements of a container of numbers can be easily modified so as to accept containers of integers, floating-point numbers, or any subtype of the number type.Technical subtleties in typing for the proposed mechanism are addressed in terms of an intuitive correspondence between variant parametric and bounded existential types. Then, for a rigorous argument of correctness of the proposed typing rules, we extend Featherweight GJ---an existing formal core calculus for Java with generics---with variant parametric types and prove type soundness.

References

[1]
Abadi, M., Cardelli, L., and Viswanathan, R. 1996. An interpretation of objects and object types. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (St. Petersburg Beach FL), 396--409.]]
[2]
Agesen, O., Freund, S. N., and Mitchell, J. C. 1997. Adding type parameterization to the Java language. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Atlanta, GA). 49--65.]]
[3]
America, P. and van der Linden, F. 1990. A parallel object-oriented language with inheritance and subtyping. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications/European Conference on Object-Oriented Programming (OOPSLA/ECOOP) (Ottawa, Canada). 161--168.]]
[4]
Barthe, G. and Frade, M. J. 1999. Constructor subtyping. In Proceedings of the 8th European Symposium on Programming (ESOP) Amsterdam, The Netherlands. Lecture Notes in Computer Science, vol. 1576, Springer Verlag, Berlin, Germany. 109--127.]]
[5]
Barthe, G. and van Raamsdonk, F. 2000. Constructor subtyping in the calculus of inductive constructions. In Proceedings of the 3rd International Conference on Foundations of Software Science and Computation Structures (FoSSaCS) (Berlin, Germany). Lecture Notes in Computer Science, vol. 1784, Springer Verlag, 17--34.]]
[6]
Bracha, G. 1996. The Strongtalk type system for Smalltalk. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA) Workshop on Extending the Smalltalk Language (San Jose, CA). Also available electronically through http://bracha.org/nwst.html.]]
[7]
Bracha, G. and Griswold, D. 1993. Strongtalk: Typechecking Smalltalk in a production environment. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Washington, DC). 215--230.]]
[8]
Bracha, G., Odersky, M., Stoutamire, D., and Wadler, P. 1998. Making the future safe for the past: Adding genericity to the Java programming language. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Vancouver, BC). 183--200.]]
[9]
Bruce, K. B. 1994. A paradigmatic object-oriented programming language: Design, static typing, and semantics. J. Funct. Program. 4, 2 (Apr.), 127--206. Preliminary version in POPL 1993, under the title “Safe type checking in a statically typed object-oriented programming language.”]]
[10]
Bruce, K. B., Cardelli, L., and Pierce, B. C. 1999. Comparing object encodings. Inf. Comput. 155, 108--133.]]
[11]
Bruce, K. B., Odersky, M., and Wadler, P. 1998. A statically safe alternative to virtual types. In Proceedings of the 12th European Conference on Object-Oriented Programming (ECOOP), Brussels, Belgium. Lecture Notes in Computer Science, vol. 1445. Springer Verlag, 523--549.]]
[12]
Bruce, K. B., Petersen, L., and Fiech, A. 1997. Subtyping is not a good “match” for object-oriented languages. In Proceedings of the 11th European Conference on Object-Oriented Programming (ECOOP) (Jyväskylä, Finland). Lecture Notes in Computer Science, vol. 1241. Springer Verlag, Berlin, Germany, 104--127.]]
[13]
Bruce, K. B., Schuett, A., and van Gent, R. 1995. PolyTOIL: A type-safe polymorphic object-oriented language. In Proceedings of the 9th European Conference on Object-Oriented Programming (ECOOP) (Aarhus, Denmark), W. Olthoff, Ed. Lecture Notes in Computer Science, vol. 952. Springer Verlag, Berlin, Germany 27--51.]]
[14]
Bruce, K. B. and Vanderwaart, J. C. 1999. Semantics-Driven language design: Statically type-safe virtual types in object-oriented languages. In Proceedings of the 15th Conference on the Mathematical Foundations of Programming Semantics (MFPS XV). (New Orleans, LA). Electronic Notes in Theoretical Computer Science, vol. 20. Elsevier. Available through http://www.elsevier.nl/locate/entcs/volume20.html.]]
[15]
Canning, P., Cook, W., Hill, W., Olthoff, W., and Mitchell, J. 1989. F-Bounded quantification for object-oriented programming. In Proceedings of the ACM Conference on Functional Programming and Computer Architecture (FPCA) (London, UK). 273--280.]]
[16]
Cardelli, L. 1990. Notes about Fω<:. Unpublished manuscript.]]
[17]
Cardelli, L., Martini, S., Mitchell, J. C., and Scedrov, A. 1994. An extension of system F with subtyping. Inf. Comput. 109, 1--2, 4--56. LNCS vol. 526. 750--770.]]
[18]
Cardelli, L. and Wegner, P. 1985. On understanding types, data abstraction, and polymorphism. ACM Comput. Surv. 17, 4 (Dec.), 471--522.]]
[19]
Cartwright, R. and Steele Jr., G. L. 1998. Compatible genericity with runtime types for the Java programming language. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Vancouver, BC). 201--215.]]
[20]
Compagnoni, A. B. and Pierce, B. C. 1996. Higher-Order intersection types and multiple inheritance. Math. Struct. Comput. Sci. 6, 469--501.]]
[21]
Cook, W. 1989. A proposal for making Eiffel type-safe. In Proceedings of the 3rd European Conference on Object-Oriented Programming (ECOOP) (Nottingham, UK). 57--70.]]
[22]
Day, M., Gruber, R., Liskov, B., and Myers, A. C. 1995. Subtypes vs. where clauses: Constraining parametric polymorphism. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Austin, TX). 156--168.]]
[23]
Duggan, D. and Compagnoni, A. 1999. Subtyping for object type constructors. In Informal Proceedings of the 6th International Workshop on Foundations of Object-Oriented Languages (FOOL6) (San Antonio, TX). Available through http://www.research.att.com/~kfisher/FOOL/FOOL6.html.]]
[24]
Ghelli, G. and Pierce, B. 1998. Bounded existentials and minimal typing. Theor. Comput. Sci. 193, 75--96.]]
[25]
Harper, R. and Lillibridge, M. 1994. A type-theoretic approach to higher-order modules with sharing. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (Portland, OR). 123--137.]]
[26]
Igarashi, A. and Pierce, B. C. 2002. Foundations for virtual types. Inf. Comput. 175, 1 (May), 34--49. An earlier version appeared in Proceedings of the European Conference on Object-Oriented Programming (ECOOP). LNCS 1628, 161--185.]]
[27]
Igarashi, A., Pierce, B. C., and Wadler, P. 2001a. Featherweight Java: A minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst. 23, 3 (May), 396--450. A preliminary summary appeared in Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'99) (Denver, CO). ACM SIGPLAN Notices 34, 10, 132--146.]]
[28]
Igarashi, A., Pierce, B. C., and Wadler, P. 2001b. A recipe for raw types. In Informal Proceedings of the 8th International Workshop on Foundations of Object-Oriented Languages (FOOL8) (London, UK). Available through http://www.research.att.com/~kfisher/FOOL/FOOL8.html.]]
[29]
Igarashi, A. and Viroli, M. 2002. On variance-based subtyping for parametric types. In Proceedings of the 16th European Conference on Object-Oriented Programming (ECOOP) (Málaga, Spain), B. Magnusson, Ed. Lecture Notes in Computer Science, vol. 2374. Springer Verlag, Berlin, Germany 441--469.]]
[30]
Interactive Software Engineering. 2001. An Eiffel tutorial. Available through http://www.eiffel.com/doc/online/eiffel50/intro/language/tutorial-00.ht%ml.]]
[31]
Leroy, X. 1994. Manifest types, modules, and separate compilation. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (Portland, OR). 109--122.]]
[32]
Liskov, B. 1988. Data abstraction and hierarchy. ACM SIGPLAN Notices 23, 5 (May), 17--34.]]
[33]
Madsen, O. L. and Møller-Pedersen, B. 1989. Virtual classes: A powerful mechanism in object-oriented programming. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (New Orleans, LA). 397--406.]]
[34]
Meyer, B. 1986. Genericity versus inheritance. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Portland, OR). 391--405.]]
[35]
Meyer, B. 1992. Eiffel: The Language. Prentice Hall, Upper Saddle River, NJ.]]
[36]
Mitchell, J. C. and Plotkin, G. D. 1988. Abstract types have existential types. ACM Trans. Program. Lang. Syst. 10, 3, 470--502.]]
[37]
Myers, A. C., Bank, J. A., and Liskov, B. 1997. Parameterized types for Java. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (Paris, France). 132--145.]]
[38]
Nordström, B., Petersson, K., and Smith, J. M. 1990. Programming in Martin-Löf's Type Theory. Oxford University Press, Oxford, UK. Out of print. An electronic version is available at http://www.cs.chalmers.se/Cs/Research/Logic/book.]]
[39]
Odersky, M., Altherr, P., Cremet, V., Emir, B., Maneth, S., Micheloud, S., Mihaylov, N., Schinz, M., Stenman, E., and Zenger, M. 2004. An overview of the Scala programming language. Tech. Rep. IC/2004/64, École Polytechnique Fédérale de Lausanne, Switzerland.]]
[40]
Odersky, M. and Wadler, P. 1997. Pizza into Java: Translating theory into practice. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (Paris, France). 146--159.]]
[41]
Palacz, K. and Vitek, J. 2003. Subtype tests in real time. In Proceedings of the 17th European Conference on Object-Oriented Programming (ECOOP) (Darmstadt, Germany), L. Cardelli, Ed. Lecture Notes in Computer Science, vol. 2743. Springer Verlag, Berlin, Germany, 378--404.]]
[42]
Pierce, B. C. 1994. Bounded quantification is undecidable. Inf. Comput. 112, 1 (July), 131--165. Also in Theoretical Aspects of Object-Oriented Programming: Types, Semantics, and Language Design. Carl A. Gunter and John C. Mitchell, Eds. MIT Press, Cambridge, MA.]]
[43]
Pierce, B. C. and Turner, D. N. 1994. Simple type-theoretic foundations for object-oriented programming. J. Funct. Program. 4, 2 (Apr.), 207--247.]]
[44]
Raynaund, O. and Thierry, E. 2001. A quasioptimal bit-vector encoding of tree hierarchies: Application to efficient type inclusion tests. In Proceedings of the 15th European Conference on Object-Oriented Programming (ECOOP) (Budapest, Hungary). Lecture Notes in Computer Science, vol. 2072. Springer Verlag, Berlin, Germany, 165--180.]]
[45]
Steffen, M. 1998. Polarized higher-order subtyping. Ph.D. thesis, Universität Erlangen-Nürnberg.]]
[46]
Sun Microsystems. 1998. Adding generic types to the Java programming language. Java Specification Request JSR-000014, http://jcp.org/jsr/detail/014.jsp.]]
[47]
Syme, D. and Kennedy, A. 2001. Design and implementation of generics for the .NET common language runtime. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI) (Snowbird, UT). Related information is available through http://research.microsoft.com/projects/clrgen/.]]
[48]
Thorup, K. K. 1997. Genericity in Java with virtual types. In Proceedings of the 11th European Conference on Object-Oriented Programming (ECOOP) (Jyväskylä, Finland). Lecture Notes in Computer Science, vol. 1241. Springer Verlag, Berlin, Germany, 444--471.]]
[49]
Thorup, K. K. and Torgersen, M. 1999. Unifying genericity: Combining the benefits of virtual types and parameterized classes. In Proceedings of the 13th European Conference on Object-Oriented Programming (ECOOP) (Lisbon, Portugal). Lecture Notes in Computer Science, vol. 1628. Springer Verlag, 186--204.]]
[50]
Torgersen, M. 1998. Virtual types are statically safe. In Informal Proceedings of the 5th International Workshop on Foundations of Object-Oriented Languages (FOOL5) (San Diego, CA). Available through http://www.research.att.com/~kfisher/FOOL/FOOL5.html.]]
[51]
Torgersen, M., Hansen, C. P., Ernst, E., von der Ahé, P., Bracha, G., and Gafter, N. 2004. Adding wildcards to the Java programming language. In Proceedings of the ACM Symposium on Applied Computing (SAC) (Nicosia, Cyprus), 1289--1296.]]
[52]
Viroli, M. 2003. A type-passing approach for the implementation of parametric methods in Java. Comput. J. 46, 3, 263--294.]]
[53]
Viroli, M. and Natali, A. 2000. Parametric polymorphism in Java: An approach to translation based on reflective features. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA) (Minneapolis, MN). 146--165.]]
[54]
Wright, A. K. and Felleisen, M. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1 (Nov.), 38--94.]]

Cited By

View all
  • (2024)Extended Polymorphism Semantics for fUML Models2024 50th Euromicro Conference on Software Engineering and Advanced Applications (SEAA)10.1109/SEAA64295.2024.00030(142-151)Online publication date: 28-Aug-2024
  • (2022)Structural refinement typesProceedings of the 7th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3546196.3550163(15-27)Online publication date: 6-Sep-2022
  • (2019)CallƐ: an effect system for method callsProceedings of the 2019 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3359591.3359731(32-45)Online publication date: 23-Oct-2019
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Transactions on Programming Languages and Systems
ACM Transactions on Programming Languages and Systems  Volume 28, Issue 5
September 2006
171 pages
ISSN:0164-0925
EISSN:1558-4593
DOI:10.1145/1152649
Issue’s Table of Contents

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 01 September 2006
Published in TOPLAS Volume 28, Issue 5

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Generic classes
  2. Java
  3. language design
  4. language semantics
  5. subtyping
  6. variance

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)79
  • Downloads (Last 6 weeks)19
Reflects downloads up to 09 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Extended Polymorphism Semantics for fUML Models2024 50th Euromicro Conference on Software Engineering and Advanced Applications (SEAA)10.1109/SEAA64295.2024.00030(142-151)Online publication date: 28-Aug-2024
  • (2022)Structural refinement typesProceedings of the 7th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3546196.3550163(15-27)Online publication date: 6-Sep-2022
  • (2019)CallƐ: an effect system for method callsProceedings of the 2019 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3359591.3359731(32-45)Online publication date: 23-Oct-2019
  • (2019)Polymorphic symmetric multiple dispatch with varianceProceedings of the ACM on Programming Languages10.1145/32903243:POPL(1-28)Online publication date: 2-Jan-2019
  • (2016)ThisType for Object-Oriented LanguagesACM Transactions on Programming Languages and Systems10.1145/288839238:3(1-66)Online publication date: 8-Apr-2016
  • (2015)IsoLATEProceedings of the 24th European Symposium on Programming on Programming Languages and Systems - Volume 903210.1007/978-3-662-46669-8_11(257-282)Online publication date: 11-Apr-2015
  • (2014)Refactoring Java generics by inferring wildcards, in practiceACM SIGPLAN Notices10.1145/2714064.266020349:10(271-290)Online publication date: 15-Oct-2014
  • (2014)Refactoring Java generics by inferring wildcards, in practiceProceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications10.1145/2660193.2660203(271-290)Online publication date: 15-Oct-2014
  • (2013)ImmutabilityAliasing in Object-Oriented Programming10.5555/2554511.2554525(233-269)Online publication date: 1-Jan-2013
  • (2013)ImmutabilityAliasing in Object-Oriented Programming. Types, Analysis and Verification10.1007/978-3-642-36946-9_9(233-269)Online publication date: 2013
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media