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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
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)
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)
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)
ECMA International. ECMA Standard 335: Common Language Infrastructure, 3rd edn. (June 2005) Available at http://www.ecma-international.org/publications/standards/Ecma-335.htm
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)
Hejlsberg, A., Wiltamuth, S., Golde, P.: C# version 2.0 specification (2005), See http://msdn.microsoft.com/vcsharp/team/language/default.aspx
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)
Igarashi, A., Viroli, M.: Variant parametric types: A flexible subtyping scheme for generics. ACM Transactions on Programming Languages and Systems (TOPLAS) (to appear, 2006)
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)
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)
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/
Odersky, M., Zenger, M.: Scalable component abstractions. In: Object-Oriented Programming: Systems, Languages, Applications (OOPSLA), ACM Press, New York (2005)
Pierce, B.C.: Bounded quantification is undecidable. Information and Computation 112(1), 131–165 (1994)
Pottier, F.: Simplifying subtyping constraints: a theory. Information and Computation 170(2), 153–183 (2001)
Sestoft, P., Hansen, H.I.: C# Precisely. MIT Press, Cambridge (2004)
Torgersen, M., Ernst, E., Hansen, C.P.: Wild FJ. In: Workshop on Foundations of Object-Oriented Languages (FOOL) (January 2005)
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)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)