Hacker News new | ask | show | jobs
by ohnoes2016 3533 days ago
> For value types that's not a problem because they don't support subclassing anyway.

Could you please provide a reference for this? Even a broad one like "a post on the Valhalla mailing list during the past summer" would be very welcome.

I'm eagerly awaiting for this feature and not being able to extend user-defined value types would be a bummer.

2 comments

You'll have to search for a reference (I don't have one off hand), but obviously value types cannot possibly support subclassing. Why is that a bummer? That's how you'd want value types to behave and the only way they can[1] (without introducing explicit pointers and complex typing rules). Also, why would you ever want to subclass value types? It serves no purpose. Value types, however, will be able to implement interfaces, which, also, is exactly what you'd want.

[1]: For example, if B is a subclass of the value type A, what do you think would happen when you store a value of type B in an array of type A?

The video I linked to above talks about the restrictions (8m20s) placed on value types:

  * They have no identity.
  * Because they have no identity == comparisons is based on their data.
  * They cannot have super classes or sub classes (they can implement interfaces though.)
  * They are immutable.
  * They cannot be null.
https://www.youtube.com/watch?v=Tc9vs_HFHVo&list=PLX8CzqL3Ar...