Skip to main content

Variance and Generalized Constraints for C\(^{\sharp}\) Generics

  • Conference paper
ECOOP 2006 – Object-Oriented Programming (ECOOP 2006)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 4067))

Included in the following conference series:

Abstract

Generic types in C\(^{\sharp}\) behave invariantly with respect to subtyping. We propose a system of type-safe variance for C\(^{\sharp}\) that supports the declaration of covariant and contravariant type parameters on generic types. To support more widespread application of variance we also generalize the existing constraint mechanism with arbitrary subtype assertions on classes and methods. This extension is useful even in the absence of variance, and subsumes equational constraints proposed for Generalized Algebraic Data Types (GADTs). We formalize the subtype relation in both declarative and syntax-directed style, and describe and prove the correctness of algorithms for constraint closure and subtyping. Finally, we formalize and prove a type safety theorem for a featherweight language with variant classes and generalized constraints.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. America, P., van der Linden, F.: 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 1990), pp. 161–168. ACM Press, New York (1990)

    Google Scholar 

  2. Cartwright, R., Steele, G.L.: Compatible genericity with run-time types for the Java programming language. In: Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), Vancouver, October 1998, ACM Press, New York (1998)

    Google Scholar 

  3. Castagna, G., Pierce, B.: Decidable bounded quantification. In: Proceedings of the Twenty-First ACM SIGPLAN–SIGACT Symposium on Principles of Programming Languages (POPL), Portland, Oregon, January 1994, ACM Press, New York (1994)

    Google Scholar 

  4. ECMA International. ECMA Standard 335: Common Language Infrastructure, 3rd edn. (June 2005) Available at http://www.ecma-international.org/publications/standards/Ecma-335.htm

  5. Fruja, N.G.: Type Safety of Generics for the.NET Common Language Runtime. In: Sestoft, P. (ed.) ESOP 2006 and ETAPS 2006. LNCS, vol. 3924, pp. 325–341. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  6. Hejlsberg, A., Wiltamuth, S., Golde, P.: C# version 2.0 specification (2005), See http://msdn.microsoft.com/vcsharp/team/language/default.aspx

  7. Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. ACM Trans. Program. Lang. Syst. 23(3), 396–450 (2001)

    Article  Google Scholar 

  8. Igarashi, A., Viroli, M.: Variant parametric types: A flexible subtyping scheme for generics. ACM Transactions on Programming Languages and Systems (TOPLAS) (to appear, 2006)

    Google Scholar 

  9. Kennedy, A., Syme, D.: Transposing F to C\(^{\sharp}\): Expressivity of parametric polymorphism in an object-oriented language. Concurrency and Computation: Practice and Experience 16, 707–733 (2004)

    Article  Google Scholar 

  10. Kennedy, A.J., Russo, C.V.: Generalized algebraic data types and object-oriented programming. In: Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), San Diego, October 2005, ACM Press, New York (2005)

    Google Scholar 

  11. Odersky, M., Altherr, P., Cremet, V., Emir, B., Micheloud, S., Mihaylov, N., Schinz, M., Stenman, E., Zenger, M.: The Scala language specification (2005), Available from http://scala.epfl.ch/

  12. Odersky, M., Zenger, M.: Scalable component abstractions. In: Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), ACM Press, New York (2005)

    Google Scholar 

  13. Pierce, B.C.: Bounded quantification is undecidable. Information and Computation 112(1), 131–165 (1994)

    Article  MATH  MathSciNet  Google Scholar 

  14. Pottier, F.: Simplifying subtyping constraints: a theory. Information and Computation 170(2), 153–183 (2001)

    Article  MATH  MathSciNet  Google Scholar 

  15. Sestoft, P., Hansen, H.I.: C# Precisely. MIT Press, Cambridge (2004)

    Google Scholar 

  16. Torgersen, M., Ernst, E., Hansen, C.P.: Wild FJ. In: Workshop on Foundations of Object-Oriented Languages (FOOL) (January 2005)

    Google Scholar 

  17. Trifonov, V., Smith, S.: Subtyping constrained types. In: Cousot, R., Schmidt, D.A. (eds.) SAS 1996. LNCS, vol. 1145, pp. 349–365. Springer, Heidelberg (1996)

    Google Scholar 

  18. Viroli, M., Natali, A.: Parametric polymorphism in Java through the homogeneous translation LM: Gathering type descriptors at load-time. Technical Report DEIS-LIA-00-001, Università degli Studi di Bologna (April 2000)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2006 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Emir, B., Kennedy, A., Russo, C., Yu, D. (2006). Variance and Generalized Constraints for C\(^{\sharp}\) Generics. In: Thomas, D. (eds) ECOOP 2006 – Object-Oriented Programming. ECOOP 2006. Lecture Notes in Computer Science, vol 4067. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11785477_18

Download citation

  • DOI: https://doi.org/10.1007/11785477_18

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-35726-1

  • Online ISBN: 978-3-540-35727-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics