◀ THE FOLD0ROOT.AI // WORLD II · BOSS · THE WALL◆ .dlw.fold
THE FOLD / BOSS / THE WALL / THE VARIANCE

THE VARIANCE

variance is about the direction, not the container
1 WHAT IT IS · WHAT IT DOES · FACT OR FICTION
If a Dog is an Animal, is an array of Dogs an array of Animals? Reading, yes. Writing, no — and a language that says yes to both has to check at runtime what its type system already claimed to know.

LIT verified live, every operation enumerated. 5 operations on an Array[Dog] viewed as Array[Animal]. Covariance allows all 5, of which 2 are unsound — writing an Animal or a Cat into an array of Dogs. Invariance allows the 3 sound ones and 0 unsound. The middle path, allowing the subtyping and checking writes at runtime, needs a check on 3 operations.
2 HOW IT WAS WEAVED · AI + HUMAN
Java and C# both made arrays covariant and both pay for it with a runtime store check; this is the standard example of a deliberately unsound rule kept for usability.

AVAN (AI) enumerated the operations instead of stating the rule, because the rule is easy to agree with and the count is what shows the cost. 2 unsound operations is not a hypothetical — it is the exhaustive list of what covariance lets through, and it is why the check exists.
3 ONE DIMENSION
Five operations, three rules.
4 TWO DIMENSIONS · INTERACTIVE
Pick a rule and try each operation.
5 THREE DIMENSIONS + AVAN’S INVERSE
The green forward object: a container that reads one way.
AVAN’s addition (the inverse-companion): the forward reading is that covariant arrays are unsound. The inverse is that the unsoundness is entirely in the writing, and a read-only array is covariant with no cost at all. Variance is not a property of the container but of the direction the values move through it, and the array only fails because it does both. Read backwards, the languages that got this right did not fix variance — they split the type, and everything that reads is covariant, everything that writes is contravariant, and only the thing that does both has to choose.
LIT 5 operations on an Array[Dog] viewed as an Array[Animal], enumerated exhaustively: covariance allows all 5 of which 2 are unsound - writing an Animal or a Cat into an array of Dogs - while invariance allows the 3 sound ones and 0 unsound, and the middle path of allowing the subtyping with runtime checks needs a check on 3 operations

FIG Java and C# both made arrays covariant and both pay for it with a runtime store check; this is the standard example of a deliberately unsound rule kept for usability. AVAN enumerated the operations instead of stating the rule, because the rule is easy to agree with and the count is what shows the cost. 2 unsound operations is the exhaustive list of what covariance lets through, and it is why the check exists.
◆ sealed .dlw.fold → folded to ROOT_0 · a sphere of THE WALL · David Lee Wise (ROOT0), with AVAN