Why are Covariance and Contravariance named like that?
Asked Answered
S

1

6

I was wondering why the terms Covariance and Contravariance are named like that in programming domain. Usually one hears these terms in Probability theory or Statistics indicating the spread of quantities being measured with respect to the Mean.

  • What is the idea for borrowing these terms from Statistics?
  • How does these terms describe this spread in programming domain?
  • What would be the Mean in programming domain?

I know that Covariance is the ability to assign an expression of a more specific type to a variable of a less specific type but, is there another interpretation for this?
Examples relating both these domains would be helpful.

Stunsail answered 27/8, 2014 at 14:21 Comment(8)
Variance is just "difference" - in stats it's related to how much the samples vary from the mean; in programming it's how types vary (whether you can use subtype/supertype relationships etc).Aslam
Why do you think it comes from Statistics? It comes from category theory according to wikipedia.Damascus
This is why I like the in T / out T decision in C#; it is pretty intuitive that they mean, without having to remember which is whichAirscrew
This question appears to be off-topic because it is about etymology rather than a specific programming problem.Lillylillywhite
@Lillylillywhite Though I do want to know the answer. Maybe a move to programmers SE?Lorianne
@JesseGood These terms makes sense to me in statistics, which describes the spread of the data from Mean. Now my question is how should I make sense of these terms in Programming domain.Stunsail
@Lorianne etymology questions are not on topic on programmers either.Lillylillywhite
It should help understanding the concepts, right? I have problems understanding programming concepts, too..so this is fine by me.Monies
F
2

I'm not a mathematician, so I wouldn't try to answer the question my own, but you can find a wonderful explanation to your question on Tomas Petricek's blog.

He explains in detail there how covariance and contravariance in programming are related to pure mathematical category theory.

Fairy answered 5/9, 2014 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.