NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Why isn't mutable a subtype of immutable, or vice versa? (crumbles.blog)
raincole 21 seconds ago [-]
In other words, immutable != read only.

In C# ReadOnlyCollection<T> and ImmutableArray<T> are two completely different things for the exact reason.

zkmon 3 minutes ago [-]
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.
gus_massa 12 hours ago [-]
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.
comrade1234 37 minutes ago [-]
Isn't NSMutableArray a subclass of NSArray in a few languages?
catoc 9 minutes ago [-]
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

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 06:21:40 GMT+0000 (Coordinated Universal Time) with Vercel.