4 ms·
Yeah I think our arguments overlap in some ways. > That's all. Because our current languages are this way doesn't mean that the two concepts cannot be reconcil
by stefncb 3y ago
Yeah I think our arguments overlap in some ways.
> That's all. Because our current languages are this way doesn't mean that the two concepts cannot be reconciliated or that one is just better than the other.
I don't think I agree with this though, I believe they're fundamentally different. The whole point of structural constraints is that they don't need the type to be aware of them. The point of nominal constraints though is that they require the type to explicitly acknowledge them.
In an ideal situation, everyone names and types things the same ('logical') way, so structural constraints 'just work'. A type implements has_organ, and an interface requires has_organ, and the type is automatically compatible with the interface.
A nominal system is the opposite though; the type explicitly understands what a specific interface implies and formally states it.
I just can't see how there's a subset-superset relationship, or how they can somehow be reconciled.
- aatd86 3y agoOne way to see it is that a type has a given methods located in a given namespace in the nominal type system. A nominal type system doesn't necessarily enforce semantics either. It just enforces the location of a method definition. Seen that way, because the relation is dual, one could indeed claim that a structural interface is a nominal interface where the name constraint is elided. But just as in subtyping, one less constraint also means bigger set. Of course if one were to decide that an object satisfying a nominal interface doesn't satisfy the structural interface obtained by ignoring the namespace, then I'd agree as well, these concepts would be disjoint. I don't think they are though but I don't know of a language that ever mixed both either.
- ceceron 3y agoAFAIK Python [optional] type system supports both. The nominal types are the "common" types, while the protocols [1] are structural. It's quite cool, actually :) [1] https://peps.python.org/pep-0544/ https://peps.python.org/pep-0544/