The fact that it requires so much explanation, indicates the level of degradation in the reasoning ability of the audience. A value of a subtype shall deliver all of the expectations of its super type, because it is wearing both the hats of super type and sub type.
Yep, I wondered that for a few optimizations in Racket. It's harder than it looks, probably something about covariant or contravariant types, I gave up.
The fact that it requires so much explanation, indicates the level of degradation in the reasoning ability of the audience. A value of a subtype shall deliver all of the expectations of its super type, because it is wearing both the hats of super type and sub type.
In other words, immutable != read only.
In C# ReadOnlyCollection<T> and ImmutableArray<T> are two completely different things for this exact reason.
Yep, I wondered that for a few optimizations in Racket. It's harder than it looks, probably something about covariant or contravariant types, I gave up.
Isn't NSMutableArray a subclass of NSArray in a few languages?
Yes, that’s ObjC, any NSMutableArray is an NSArray (and an NSObject) - classes passed by reference.
Swift is completely different. Standard arrays are structures, always mutable - value types passed by value