# Covariance and contravariance: conflict without a cause

@article{Castagna1995CovarianceAC, title={Covariance and contravariance: conflict without a cause}, author={Giuseppe Castagna}, journal={ACM Trans. Program. Lang. Syst.}, year={1995}, volume={17}, pages={431-447} }

In type-theoretic research on object-oriented programming, the issue of “covariance versus contravariance” is a topic of continuing debate. In this short note we argue that covariance and contravariance appropriately characterize two distinct and independent mechanisms. The so-called contravariance rule correctly captures the subtyping relation (that relation which establishes which sets of functions can replace another given set in every context). A covariant relation, instead, characterizes…

## Topics from this paper

## 212 Citations

Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers)

- Computer ScienceLog. Methods Comput. Sci.
- 2020

This work reexamines the result of an article arguing that covariant and contravariant specialization of method parameters in object-oriented programming had different purposes and deduced that, not only they could, but actually they should both coexist in the same language.

Type-Safe Compilation of Covariant Specialization: A Practical Case

- Computer ScienceECOOP
- 1996

This work proposes a modification to the O2 compiler that adds code to correct previously ill-typed computations that arise from the use of covariant specialization, and ensures the type safety (w.r.t. covariance) of the program.

Integration of parametric and “ad hoc” second order polymorphism in a calculus with subtyping

- Mathematics, Computer ScienceFormal Aspects of Computing
- 2005

An extension ofF≤ to which functions that dispatch on different terms according to the type they receive as argument are added, enriching the explicit parametric polymorphism of F≤ by an explicit “ad hoc” polymorphism (according to the classification of Str67).

An Operational Approach to the Semantics of Classes: Application to Type Checking

- Mathematics, Computer ScienceProgramming and Computer Software
- 2004

The model, called the Formal Class model, is an intermediate level between the algebraic specification of data type, and the implementation within an object-oriented language, equipped with an operational semantics based on conditional term rewriting.

Constrained Matching is Type Safe

- Computer ScienceDBPL
- 1997

It is proved that this constrained matching guarantees type safe substitutability even in situations where matching alone would not, and can capture subtleties that go far beyond the level of expressiveness of object-oriented type systems.

"Real World" as an Argument for Covariant Specialization in Programming and Modeling

- Computer ScienceOOIS Workshops
- 2002

It is claimed that type errors are part of the real world, so they should be taken into account at all stages of software development, and modeling as well as programming languages should adopt a covariant policy.

ECOOP’ 99 — Object-Oriented Programming

- Computer ScienceLecture Notes in Computer Science
- 1999

A mathematical model and language for the formulation of assertions about objects and pointers are introduced, and a graphical calculus may help in reasoning about program correctness, which deals with both garbage-collected heaps and the other kind.

A Theory of Objects

- Computer ScienceMonographs in Computer Science
- 1996

This book takes a novel approach to the understanding of object-oriented languages by introducing object calculi and developing a theory of objects around them, which covers both the semantics of objects and their typing rules.

Correspondence polymorphism for object-oriented languages

- Computer ScienceOOPSLA '99
- 1999

A new form of polymorphism for object-oriented languages, called correspondence polymorphism, that lies in a different dimension than either parametric or subtype polymorphism is proposed, and formal type rules and an operational semantics for LCP are presented.

A lambda calculus of objects with self-inflicted extension

- Computer ScienceOOPSLA '98
- 1998

A sound type system is presented for this calculus which guarantees that evaluating a well-typed expression will never yield a message-not-found run-time error and the resulting calculus appears to be a good starting point for a rigorous mathematical analysis of class-based languages.

## References

SHOWING 1-10 OF 52 REFERENCES

Type-Safe Compilation of Covariant Specialization: A Practical Case

- Computer ScienceECOOP
- 1996

This work proposes a modification to the O2 compiler that adds code to correct previously ill-typed computations that arise from the use of covariant specialization, and ensures the type safety (w.r.t. covariance) of the program.

A Calculus for Overloaded Functions with Subtyping

- Mathematics
- 1995

We present a simple extension of typed ?-calculus where functions can be overloaded by putting different "branches of code" together. When the function is applied, the branch to execute is chosen…

A calculus for overloaded functions with subtyping

- Computer ScienceLFP '92
- 1992

It is shown that this calculus provides a foundation for typed object-oriented languages which solves some of the problems of the standard record-based approach and provides a type-discipline for a relevant fragment of the “core framework” of CLOS.

Developments in Object-Oriented Type Systems

- Computer Science
- 1994

This work presents and discusses an interplay between OO and functional languages taking place over the last decade, a source of heated debate and some self-reeection in both camps.

Programming with intersection types and bounded polymorphism

- Mathematics
- 1992

This thesis unifies and extends prior work on intersection types and bounded quantification, previously studied only in isolation, by investigating theoretical and practical aspects of a typed…

Intersection and Union Types: Syntax and Semantics

- Computer Science, MathematicsInf. Comput.
- 1995

Type assignment systems with intersection and union types are introduced. Although the subject reduction property with respect to s-reduction does not hold for a natural deduction-like system, we…

A semantics of multiple inheritance

- 1988

There are two major ways of structuring data in programming languages. The first and common one, used for example in Pascal, can be said to derive from standard branches of mathematics. Data are…

A Meta-Language for Typed Object-Oriented Languages

- Computer ScienceFSTTCS
- 1993

This paper defines a meta-language based on λ& and shows, by a practical example, how it can be used it to prove properties of a language, and defines a toy object-oriented language and its type-checking algorithm, and translates this toy language into this meta- language.

A static type system for message passing

- OOPSLA '91
- 1991

An atomic linguistic construct is defined to capture the notion of message passing, and a static and strong type system, based on subtyping, is defined for this construct.

OBJ: Programming with Equalities, Subsorts, Overloading and Parameterization

- Mathematics, Computer ScienceALP
- 1988

OBJ is a wide-spectrum language that elegantly integrates coding, specification and design into a single framework that supports overloading and subtypes.