Computing Reviews

Covariance and contravariance
Castagna G. ACM Transactions on Programming Languages and Systems17(3):431-447,1995.Type:Article
Date Reviewed: 08/01/96

Ever since the O2 data model [1] and later the Eiffel language [2] introduced the concept of covariant specialization of methods, type theorists have argued whether it is better to use covariant or contravariant specialization for the methods in object-oriented languages. Castagna claims that this is a conflict without a cause.

It is generally believed that one has to use contravariance when static type safety is required, but that covariance is more natural, flexible, and expressive. Both approaches are very appealing, but they seem totally incompatible. As Castagna points out, however, there is a flaw in the comparison. He goes on to show that both covariance and contravariance can be used in a way that guarantees type safety.

He also contributes decisively to the debate, showing that the two concepts are not antagonistic, but that each has its own use. Covariance captures code specialization where the definition of new code replaces old definitions in some particular cases. Contravariance captures the subtyping relation, which states which sets of functions can replace another given set in every context.

Castagna keeps the presentation informal and at the same time precise. For those interested in type theory and type systems in object-oriented programming languages, this paper is definitely worth reading.


1)

Lécluse, C.; Richard, P.; and Vélez, F. O2, an object-oriented data model. In Proceedings of the 1988 ACM SIGMOD International Conference on Management of Data (Chicago, IL, June 1–3, 1988), H. Boral, Ed. ACM, New York, 1988, 424–433.


2)

Meyer, B. Eiffel: the language. Prentice-Hall, Englewood Cliffs, NJ, 1991.

Reviewer:  D. B. Lange Review #: CR119384 (9608-0612)

Reproduction in whole or in part without permission is prohibited.   Copyright 2024 ComputingReviews.com™
Terms of Use
| Privacy Policy