AssociatedTypes lookup won't work for subtypes in current scheme. #11

Closed
opened 2023-08-22 04:56:10 +00:00 by glen · 0 comments
Owner

The current strategy for looking up associated types will fail once we want two distinct types, like DenseMatrix and Matrix, such that one extends the other.

That's because there is one key for each type, and in the type for that key it specifies (each of) the associated types, as well as the type itself. The lookup then considers just the keys corresponding to types that the parameter type extends, and essentially unions them all (by indexing the whole AssociatedTypes interface by the matching keys).

But this means that if Sub extends Sup but we want them both to be types in the system, then we have in AssociatedTypes:

Sup: {
  type: Sup,
  one:  OneSup,
  // etc.
},
Sub: {
  type: Sub,
  one: OneSub,
  // etc.
}

Now just consider looking up the associated type type of Sub. We want it to be Sub. But Sub extends both the Sup and Sub types, so both of those keys match, so the lookup returns the union of Sup and Sub, which is just Sup, not sub.

It looks like we need to switch to taking the intersection of all of the clauses where the given type extends the associated type. I think that will work.

The current strategy for looking up associated types will fail once we want two distinct types, like DenseMatrix and Matrix, such that one extends the other. That's because there is one key for each type, and in the type for that key it specifies (each of) the associated types, as well as the type itself. The lookup then considers just the keys corresponding to types that the parameter type extends, and essentially unions them all (by indexing the whole AssociatedTypes interface by the matching keys). But this means that if Sub extends Sup but we want them both to be types in the system, then we have in AssociatedTypes: ``` Sup: { type: Sup, one: OneSup, // etc. }, Sub: { type: Sub, one: OneSub, // etc. } ``` Now just consider looking up the associated type `type` of Sub. We want it to be Sub. But Sub extends both the Sup and Sub types, so both of those keys match, so the lookup returns the union of Sup and Sub, which is just Sup, not sub. It looks like we need to switch to taking the _intersection_ of all of the clauses where the given type extends the associated type. I _think_ that will work.
glen added the
bug
label 2023-08-22 05:01:00 +00:00
glen closed this issue 2023-08-23 16:52:17 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: glen/typocomath#11
No description provided.