When I read the beginning of Type Class Derivation | Scala 3 Language Reference | Scala Documentation, I think to myself that I might be able to do the Scala equivalent of Haskell’s
data RGB = Red | Green | Blue deriving(Eq,Ord,Show)
for Ordering, i.e.
enum RGB derives Ordering: case Red, Green, Blue
But that results in “value derived is not a member of object scala.math.Ordering”, so I end up doing this:
enum RGB: case Red, Green, Blue given Ordering[RGB] with def compare(x: RGB, y: RGB): Int = x.ordinal compare y.ordinal import RGB._ assert( List(Green, Red, Blue).sorted == List(Red, Green, Blue) )
Am I missing some trick?