HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[haxe.org/manual] Effects of variance and access modifiers #84

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

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

JonasSonn commented 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):

Aurel300 commented 3 years ago

@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: