2 ms·
> That also means that you can't have mutable values, static types and subtyping in the same language Yes you can. You just need to make a clean separation bet
by kccqzy 9y ago
> That also means that you can't have mutable values, static types and subtyping in the same language
Yes you can. You just need to make a clean separation between mutable variables and immutable variables. Then mutable variables must be invariant, and immutable variables can enjoy subtyping.
Alternatively, classify mutable variables further and make references carry information about whether only reading/writing is allowed through this reference. Then read-references enjoy the usual covariant subtyping, and write-references enjoy contravariant subtyping.
- tome 9y agoAgreed, although I'd go a step further. A mutable variable has a type of reads and a type of writes. They vary in opposite directions. If you constrain them to be the same then they must therefore not vary at all.