17008, “vasslitvinov”, “CG: semantics of associated types”, “2021-01-26T14:27:37Z”
main issue: #8629
“Associated types” are introduced in like-named section in CHIP 2, which immediately follows Example 3. For example: Stack.itemType
here:
interface Stack {
type itemType;
proc Self.push(x : itemType);
proc Self.pop(): itemType;
proc Self.isEmpty(): bool;
}
Design question: how is type itemType;
different than proc itemType type;
? Perhaps the former allows:
- the “Same-type constraints” and “Nested requirements” features (see CHIP2)
- being used as an argument type in other required functions
Design question: how does an implements
statement define the corresponding associated type(s)? Some options:
- implicit for a single-argument interface, ex.
record MyRecord {
type itemType;
}
implements Stack(MyRecord(int)); // itemType = int
-
implicit for a multi-argument interface: same as above, using the first argument
-
explicit for any number of arguments, ex.
MyRecord implements Stack {
itemType = int;
}