Advertisement

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

  • Burak Emir
  • Andrew Kennedy
  • Claudio Russo
  • Dachuan Yu
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4067)

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.

Keywords

Generalize Constraint Class Hierarchy Type Soundness Equational Constraint Subtype Relation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 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. 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. 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. 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. 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)CrossRefGoogle Scholar
  6. 6.
    Hejlsberg, A., Wiltamuth, S., Golde, P.: C# version 2.0 specification (2005), See http://msdn.microsoft.com/vcsharp/team/language/default.aspx
  7. 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)CrossRefGoogle Scholar
  8. 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. 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)CrossRefGoogle Scholar
  10. 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. 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. 12.
    Odersky, M., Zenger, M.: Scalable component abstractions. In: Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), ACM Press, New York (2005)Google Scholar
  13. 13.
    Pierce, B.C.: Bounded quantification is undecidable. Information and Computation 112(1), 131–165 (1994)MATHCrossRefMathSciNetGoogle Scholar
  14. 14.
    Pottier, F.: Simplifying subtyping constraints: a theory. Information and Computation 170(2), 153–183 (2001)MATHCrossRefMathSciNetGoogle Scholar
  15. 15.
    Sestoft, P., Hansen, H.I.: C# Precisely. MIT Press, Cambridge (2004)Google Scholar
  16. 16.
    Torgersen, M., Ernst, E., Hansen, C.P.: Wild FJ. In: Workshop on Foundations of Object-Oriented Languages (FOOL) (January 2005)Google Scholar
  17. 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. 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

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Burak Emir
    • 1
  • Andrew Kennedy
    • 2
  • Claudio Russo
    • 2
  • Dachuan Yu
    • 3
  1. 1.EPFLLausanneSwitzerland
  2. 2.Microsoft ResearchCambridgeU.K.
  3. 3.DoCoMo Communications LaboratoriesSan JoseUSA

Personalised recommendations