Covariance and Contravariance: Conflict without a Cause
G. Castagna. ACM Transactions on Programming Languages and Systems, 17 (3):
431--447(May 1995)
Abstract
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 the specialization of
code (i.e., the definition of new code which replaces old definitions
in some particular cases). Therefore, covariance and
contravariance are not opposing views, but distinct concepts that each
have their place in object-oriented systems. Both can (and should) be
integrated in a type-safe manner in object-oriented languages. We also
show that the independence of the two mechanisms is not characteristic
of a particular model but is valid in general, since covariant
specialization is present in record-based models, although it is
hidden by a deficiency of all existing calculi that realize this
model. As an aside, we show that the $łambda$-calculus can be taken
as the basic calculus for both an overloading-based and a record-based
model. Using this approach, one not only obtains a more uniform vision
of object-oriented type theories, but in the case of the record-based
approach, one also gains multiple dispatching, a feature that existing
record-based models do not capture
ACM Transactions on Programming Languages and Systems
number
3
pages
431--447
volume
17
issn
0164-0925
bibdate
Fri Jan 5 07:58:42 MST 1996
coden
ATPSDT
subject
F.3.3: Theory of Computation, LOGICS AND MEANINGS OF PROGRAMS,
Studies of Program Constructs, Type structure. D.3.2: Software,
PROGRAMMING LANGUAGES, Language Classifications, Object-oriented
languages.
%0 Journal Article
%1 castagna1995a
%A Castagna, Giuseppe
%D 1995
%J ACM Transactions on Programming Languages and Systems
%K languages; theory
%N 3
%P 431--447
%T Covariance and Contravariance: Conflict without a Cause
%U http://www.acm.org/pubs/toc/Abstracts/0164-0925/203096.html
%V 17
%X 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 the specialization of
code (i.e., the definition of new code which replaces old definitions
in some particular cases). Therefore, covariance and
contravariance are not opposing views, but distinct concepts that each
have their place in object-oriented systems. Both can (and should) be
integrated in a type-safe manner in object-oriented languages. We also
show that the independence of the two mechanisms is not characteristic
of a particular model but is valid in general, since covariant
specialization is present in record-based models, although it is
hidden by a deficiency of all existing calculi that realize this
model. As an aside, we show that the $łambda$-calculus can be taken
as the basic calculus for both an overloading-based and a record-based
model. Using this approach, one not only obtains a more uniform vision
of object-oriented type theories, but in the case of the record-based
approach, one also gains multiple dispatching, a feature that existing
record-based models do not capture
@article{castagna1995a,
abstract = {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 {\em
subtyping} relation (that relation which establishes which sets of
functions can replace another given set in {\em every context}). A
covariant relation, instead, characterizes the {\em specialization} of
code (i.e., the definition of new code which replaces old definitions
{\em in some particular cases}). Therefore, covariance and
contravariance are not opposing views, but distinct concepts that each
have their place in object-oriented systems. Both can (and should) be
integrated in a type-safe manner in object-oriented languages. We also
show that the independence of the two mechanisms is not characteristic
of a particular model but is valid in general, since covariant
specialization is present in record-based models, although it is
hidden by a deficiency of all existing calculi that realize this
model. As an aside, we show that the $\lambda$-calculus can be taken
as the basic calculus for both an overloading-based and a record-based
model. Using this approach, one not only obtains a more uniform vision
of object-oriented type theories, but in the case of the record-based
approach, one also gains multiple dispatching, a feature that existing
record-based models do not capture},
added-at = {2006-03-09T08:15:35.000+0100},
author = {Castagna, Giuseppe},
bibdate = {Fri Jan 5 07:58:42 MST 1996},
biburl = {https://www.bibsonomy.org/bibtex/243d5d5230295f64b725e7cf98f66853b/snowball},
coden = {ATPSDT},
interhash = {4989daec71ec886baa049b09c196cc22},
intrahash = {43d5d5230295f64b725e7cf98f66853b},
issn = {0164-0925},
journal = {ACM Transactions on Programming Languages and Systems},
keywords = {languages; theory},
month = May,
number = 3,
pages = {431--447},
subject = {{\bf F.3.3}: Theory of Computation, LOGICS AND MEANINGS OF PROGRAMS,
Studies of Program Constructs, Type structure. {\bf D.3.2}: Software,
PROGRAMMING LANGUAGES, Language Classifications, Object-oriented
languages.},
timestamp = {2006-03-09T08:15:35.000+0100},
title = {Covariance and Contravariance: Conflict without a Cause},
url = {http://www.acm.org/pubs/toc/Abstracts/0164-0925/203096.html},
volume = 17,
year = 1995
}