Why isn't mutable a subtype of immutable, or vice versa?
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
Why isn't mutable a subtype of immutable, or vice versa?
Unofficial Hacker News client; not affiliated with Y Combinator.
cubefox · · focus · HN ↗
In contrast, neither are the mutable things a subset of the immutable things nor the other way round. It's not the case that everything mutable is immutable nor that everything immutable is mutable. The two types are disjoint.
ris · · focus · HN ↗
I'm currently being annoyed by python's type hinting system, which has exactly this sort of hierarchy for containers, but there's nothing stopping a caller/callee from using type-narrowing to "discover" that the underlying type is actually e.g. a (mutable) list, and then modifying it without any complaints from the type checker. The only way to enforce this would be to actually convert to an immutable implementation type, involving unnecessary copying.