3 ms·
> Arrays are covariant, and object is the base class of everything. I'm surprised that nobody's noticed that already (it's unsafe: arrays should instead be inva
by catnaroek 10y ago
> Arrays are covariant, and object is the base class of everything. I'm surprised that nobody's noticed that already (it's unsafe: arrays should instead be invariant).
The real problem is that most languages don't actually give you arrays, they just give you mutable cells containing arrays of mutable cells. Remove mutable cells from the picture, and you'll see how wonderfully covariant array types are.
Arrays are really second-class values in the vast majority of languages. The litmus test for first-class-value-ness is “Do I need to worry about the identity of the object that holds this value?” The answer should be “no” if the value is first-class.
> `var v = 1 / 0` causes FPE and core dump and dumps an ugly compiler stack trace.
Exceptions don't make much sense for handling programming errors like division by 0. What is your program supposed to do? Fix itself?
> I suspect that their virtual types are probably unsound, but haven't tried working with them.
They are indeed unsound, for pretty much the same reason covariant method arguments are unsound in Eiffel. I have an example here: https://news.ycombinator.com/item?id=11752071 https://news.ycombinator.com/item?id=11752071