You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deriving from A multiple times indirectly seems very useful to me, to encode mathematical structure. A common pattern could be "A Foo is an algbera over this signature. A Foo is said to be potatoe-like if .... A Foo is said to be carrot-like if .... A Foo is said to be complete if it is both potatoe-like and carrot-like, and ...." This would be encoded as
classFoowhere ...
classPotatoeextends Foo where ...
classCarrotextends Foo where ...
classCompleteextends Potatoe, Carrot where ...
If you refer to deriving from A both directly and indirectly (ie. exactly the example I gave), then I agree it is less clear that this might be practically useful, as, in my example, one could simply remove the direct inheritance from C to A in the definition of C, and still refer to the fields of A in those of C, because they are available through B.
The case where it might still makes sense to have this duplicate dependency is in cases where B and C have an abstraction boundary between them, and C does not know that B extends A (this could be the case because B doesn't want removing A to be a breaking change, so they don't include the fact that they inherit from A in their declared interface).
Having discretionary parents is fine and supported(*). One problem here is that Ashould come after B, since with the current order, name resolution will visit A before B even though A is a parent of B. You can check this using set_option structure.strictResolutionOrder true, where it complains about the order of the parents
classCextends A, B
/-failed to compute strict resolution order:- parent 'A' must come after parent 'B'-/
This is not the underlying problem for this issue however. Instead, it's that structure instance elaboration currently only looks for instances to fill in fields for parents that are represented as "subobjects". Supporting non-subobject parents is planned, and I'll use this issue to track the feature. Here's an an artificial example that doesn't have the strictResolutionOrder failure:
classAwherea : Unit
classBwherea : Unit
classCextends A, B
classC'extends B, A
instance : B where
a := ()
instance : C where -- fields missing: 'a'instance : C' where -- succeeds
(*) @Kha We want this because there exist class hierarchies that need them to be able to deduce strict resolution orders.
Activity
Kha commentedon Nov 15, 2024
Do you have a practical example? Deriving from
Amultiple times isn't very, and one wonders if that should even be allowed.jthulhu commentedon Nov 15, 2024
Deriving from
Amultiple times indirectly seems very useful to me, to encode mathematical structure. A common pattern could be "A Foo is an algbera over this signature. A Foo is said to be potatoe-like if .... A Foo is said to be carrot-like if .... A Foo is said to be complete if it is both potatoe-like and carrot-like, and ...." This would be encoded asIf you refer to deriving from
Aboth directly and indirectly (ie. exactly the example I gave), then I agree it is less clear that this might be practically useful, as, in my example, one could simply remove the direct inheritance fromCtoAin the definition ofC, and still refer to the fields ofAin those ofC, because they are available throughB.The case where it might still makes sense to have this duplicate dependency is in cases where
BandChave an abstraction boundary between them, andCdoes not know thatBextendsA(this could be the case becauseBdoesn't want removingAto be a breaking change, so they don't include the fact that they inherit fromAin their declared interface).kmill commentedon Nov 15, 2024
Having discretionary parents is fine and supported(*). One problem here is that
Ashould come afterB, since with the current order, name resolution will visitAbeforeBeven thoughAis a parent ofB. You can check this usingset_option structure.strictResolutionOrder true, where it complains about the order of the parentsThis is not the underlying problem for this issue however. Instead, it's that structure instance elaboration currently only looks for instances to fill in fields for parents that are represented as "subobjects". Supporting non-subobject parents is planned, and I'll use this issue to track the feature. Here's an an artificial example that doesn't have the strictResolutionOrder failure:
(*) @Kha We want this because there exist class hierarchies that need them to be able to deduce strict resolution orders.
feat: structure instance notation elaboration improvements (#7717)