3 ms·
> Covariance and contravariance are just monotonicity and anti-monotonicity I am confused. It seems that monotonicity is a property of the function itself, tha
by techno_modus 9y ago
> Covariance and contravariance are just monotonicity and anti-monotonicity
I am confused. It seems that monotonicity is a property of the function itself, that is, how it is implemented and what (type) it returns depending on what (type) it gets. In other words, we vary input value (real) type and observe what happens with the output value (real) type. Only one function is involved - monotonicity is its inherent property.
But covariance/contravariance is about '<:' relation between function signatures (the contract, not how it is implemented). Once this relation has been somehow defined, we can check, for example, if one function can be safely applied instead of another function. In other words, we vary signatures by changing input/output declared types and then decide about the relation among them.
Why do you say that monotonicity is similar or equivalent to covariance? They seem to be different properties.
- mmarx 9y agoMonotonicity is a property of functions that is relative to some ordering relation (e.g., f(x) = x + 42 as a function on natural numbers is monotone with respect to the natural ordering). In this case, that ordering relation is <:, and covariant functions are precisely those function that are monotone with respect to <:; as are contravariant functions the antitone functions with respect to <:.