Syntax for prioritising one existing ordering over another

#1
class V extends Ordered[V]
class S extends V

trait P extends Ordered[P]

I would like class S to mix in trait P. However I get a divergent implicits error when using < relop.

Is there a way of saying, when you order S, take V's ordering only and ignore P's, perhaps via an implicit, without having to reimplement the ordering logic. What would the syntax for this be?

#2

AFAICS this can’t work, just due to type erasure. Solution: Goodbye Ordered, hello Ordering.

1 Like
#3

Agreed – this is one of the classic reasons to use the typeclass-based Ordering instead of the inheritance-based Ordered: you can have more than one definition for it…