Avoiding The Need For Covariant Argument Types
The need for covariant argument types arises from strategies in object oriented languages for context-sensitive selection of the code used in method calls. This does not include the first parameter of a method call, which is the object itself, which is not contravariant.
Castagna showed that types used for runtime selection of the method are covariant, while types not used for runtime selection of the method are contravariant. In Castagna's work, examples which would suggest the usage of covariance for parameter types are treated with the usage of multiple dispatch, i.e. overriding where the right method is selected also based on the type of some arguments; applying the rule, covariance is allowed for those argument types. However, this solution cannot be applied to most programming languages, since they do not support multiple dispatch.
Note that for (static) overload resolution, the opposite rule applies: types used for compile-time method selection (i.e. parameter types) are contravariant; types not used to select the method are covariant.
These terms are also used in the context of modern programming languages that offer other functors to create new types with type variables, e.g., generic programming or parametric polymorphism, and exception handling where method definitions are enriched with annotations that indicate possible failures.
Read more about this topic: Covariance And Contravariance (computer Science)
Famous quotes containing the words avoiding the, avoiding, argument and/or types:
“The only sure way of avoiding these evils [vanity and boasting] is never to speak of yourself at all. But when, historically, you are obliged to mention yourself, take care not to drop one single word that can directly or indirectly be construed as fishing for applause.”
—Philip Dormer Stanhope, 4th Earl Chesterfield (16941773)
“Caring for children is a dance between setting appropriate limits as caretakers and avoiding unnecessary power struggles that result in unhappiness.”
—Charlotte Davis Kasl (20th century)
“A striking feature of moral and political argument in the modern world is the extent to which it is innovators, radicals, and revolutionaries who revive old doctrines, while their conservative and reactionary opponents are the inventors of new ones.”
—Alasdair Chalmers MacIntyre (b. 1929)
“As for types like my own, obscurely motivated by the conviction that our existence was worthless if we didnt make a turning point of it, we were assigned to the humanities, to poetry, philosophy, paintingthe nursery games of humankind, which had to be left behind when the age of science began. The humanities would be called upon to choose a wallpaper for the crypt, as the end drew near.”
—Saul Bellow (b. 1915)