Replies: 3 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
What do you mean by In that particular example you referenced, This is the same reason that Hence, we get this somewhat recursive dependency on the inner most type. |
Beta Was this translation helpful? Give feedback.
-
Once we have associated traits we might be able to cook something up in regards to this. |
Beta Was this translation helpful? Give feedback.
-
Since certain collection types, such as
List[T]
are defined with a generic type parameterT
that must conform toCollectionElement
, nested structures such asList[List[T]]
are allowed. However, for example, theList
type does not conform to otherCollectionElement
-based traits such asComparableCollectionElement
EqualityComparableCollectionElement
RepresentableCollectionElement
StringableCollectionElement
.This leads to limitations which are generally intuitive to a programmer, such as the following operations being disallowed:
(respective to the mentioned traits)
For instance, if we consider the
__contains__
method ofList
:this limits the
List
API for nested instances. It creates a quasi recursive dependency onEqualityComparableCollectionElement
where the most inner list's elements' type needs to conform to a trait that the list itself doesn't satisfy.I believe this is somewhat of an expression problem under the current trait system, and would really enjoy to hear potential design choices to resolve this while maintaining performance.
For instance, if we involve parametric traits, similar to Higher-Kinded Types as in languages like Haskell, perhaps something like this could be a solution:
This approach would allow for recursive comparison of nested structures.
__contains__
could be simplified to:For simple elements, it would use their
==
operator directly. For nested lists, it would trigger the recursive__eq__
we defined earlier.Perhaps there's a simpler solution?
Beta Was this translation helpful? Give feedback.
All reactions