E.g.
let f1: A -> B = ...
let f2: C -> D = f1
(...)
Applied here, the above code works if A is a subtype of C, and if B is a supertype of D.
Put concretely:
let f1: Animal -> Animal = ...
let f2: Cat -> Thing = f1
So now Animal is a subtype of a Cat, and a supertype of Thing?But I finally understand what covariance and contravariance means, so thanks!
--
Also, related, could somebody more proficient in English than I am help me understand which direction does the substitution go here?
"It says, in short, that an instance of a subclass can always be substituted for an instance of its superclass."
Is it "an instance of subclass can replace an instance of superclass", or "it can be replaced by"? Or is it context-dependent?
I ask because I'm not sure about the grammar aspect, and in my native language (Polish) we have a few ambiguities like that, which I sometimes jokingly write down with an arrow, e.g. "A can be ---substitutes for--> B" or "A can be <--substituted for-- B", to make it damn explicit which direction the word works.