Missing subtype/compatible for Lists
From Erik:
I think the definition of subtype is lacking in the spec. The spec says:
"NonEmptyList<P>
is a subtype of List<Q>
for all types P and Q where P is a subtype of Q."
But it also needs:
"List<P>
is a subtype of List<Q>
and NonEmptyList<P>
is a subtype of NonEmptyList<Q>
for all types P and Q where P is a subtype of Q."
There's a similar problem with the compatible-relation and lists (and the accept-relation in my definitions). The spec says: "Compatible is the least relation between types such that
-
P
is compatible with all supertypes of P -
LUB<P>
is compatible with all subtypes of P" But this does not cover the case with LUB in List-types, for example NEList<LUB> is only compatible with List/NEList by this definition. So I think it also needs: "and for all types P and Q where P is compatible with Q -
List<P>
is compatible withList<Q>
, -
NonEmptyList<P>
is compatible withList<Q>
, -
NonEmptyList<P>
is compatible withNonEmptyList<Q>
." However, since compatibility is a relation from argument-types to parameter-types, and all non-empty lists have typeNEList<LUB<Top>>
, then all that really needs to be added to the current spec is thatNEList<LUB<Top>>
is compatible withList<P>
andNEList<P>
for every type P.
Edited by Leif Harald Karlsen