Should an interface covariant on T ever implement an interface invariant on it?

I was reading through the Hacklang docs on Collections, and came across this curious definition [paraphrased slightly]: interface KeyedIterable ... interface ConstVector implements KeyedIterable ... Of course, KeyedIterable must be read-only with respect to Tv, and indeed it is since its methods cannot modify its type. It could be specified to be covariant on at least Tv, but isn't. I was wondering what impetus there could be to do this? Edit: I read the definition wrong, KeyedIterable is actually defined as KeyedIterable, so this definition makes perfect sense. I'm just realizing now that it's not so much "should or should not", but rather "this is never possible".

Apr 23, 2025 - 17:20
 0
Should an interface covariant on T ever implement an interface invariant on it?

I was reading through the Hacklang docs on Collections, and came across this curious definition [paraphrased slightly]:

interface KeyedIterable ...
interface ConstVector<+Tv> implements KeyedIterable  ...

Of course, KeyedIterable must be read-only with respect to Tv, and indeed it is since its methods cannot modify its type. It could be specified to be covariant on at least Tv, but isn't.

I was wondering what impetus there could be to do this?


Edit: I read the definition wrong, KeyedIterable is actually defined as KeyedIterable, so this definition makes perfect sense. I'm just realizing now that it's not so much "should or should not", but rather "this is never possible".