Open utterances-bot opened 3 years ago
Is it possible that the terms contravariance and covariance have been accidentally switched?
So that:
That is, their argument types allow contravariance (less specific types) while their return type allows covariance (more specific types):
Should be:
That is, their argument types allow covariance (less specific types) while their return type allows contravariance (more specific types):
@JonasSonn No. I'm not sure the "definition of co/contravariance" we have in the manual is good enough, but using the standard meaning of variance, function arguments are indeed contravariant. That is:
Given two types X and Y, if X "extends" Y, X is said to be a subtype of Y, X <: Y
.
When the types happen to be function types, then X -> Y <: A -> B
when:
Y <: B
, because function types are covariant in the return type; andA <: X
, because function types are contravariant in the argument type(s). Note that the order of the subtyping relation is reversed, hence the "contra".
Effects of variance and access modifiers - Haxe - The Cross-platform Toolkit
Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.
https://haxe.org/manual/class-field-override-effects.html