I’m relatively new with Scala. I’m not sure if this question should have gone in the general forum, but it seemed language lawyery so I put it here.
I’m not sure why the following code compiles:
import scala.language.strictEquality case class C(x: String => String) derives CanEqual
Shouldn’t this fail because
CanEqual is not defined on
String => String and hence can’t be derived? It would seem to me that the most obvious way to implement the deriving clause was to apply it recursively to the sub elements. I’m guessing this is how things like
Ord work also. But it seems here maybe it’s just using the Java’s
.Equals() method, which is meaningless on functions. Why not implement
CanEqual so it just recursively applies
CanEqual and fails if the sub elements don’t have the required
CanEqual trait? If this is falling back to
.Equals(), when is this actually a good idea given that the whole point of the
CanEqual class (as far as I understand) is to be explicit about defining equality, in contrast to the Java approach of just giving everything equality, even types where it doesn’t make sense?