Scala 3.1 - Inconsistent Behavior with Intersection Types in Type Classes
Could someone explain Quick question that's been bugging me - I'm working with an scenario with intersection types while implementing type classes in Scala 3.1... I've defined a type class `Show` that is meant to convert various types into a string representation. However, when I try to use an intersection type `Show[A] with Show[B]`, I'm getting unexpected results, specifically a `Type mismatch: found (Show[A] with Show[B]) required Show[C]` behavior. Here's a simplified version of my code: ```scala trait Show[A] { def show(a: A): String } given Show[Int] with { def show(a: Int): String = a.toString } given Show[String] with { def show(a: String): String = a } case class Combined[A, B](a: A, b: B) given [A, B](using showA: Show[A], showB: Show[B]): Show[Combined[A, B]] with { def show(combined: Combined[A, B]): String = s"${showA.show(combined.a)} and ${showB.show(combined.b)}" } val result = Combined(42, "hello") println(implicitly[Show[Combined[Int, String]]].show(result)) ``` When I run this, I receive the behavior mentioned above, and it seems that the scenario arises when I try to use the `Combined` type with intersection types. I've tried explicitly defining the given instances for `Show` but to no avail. I also attempted using an auxiliary type instead of directly using the intersection type, but that didn't resolve the scenario either. Any insight on why this behavior is occurring and how to properly implement intersection types in this context would be greatly appreciated. Thanks! My development environment is macOS. Am I missing something obvious? My development environment is Ubuntu 22.04. I appreciate any insights! I recently upgraded to Scala LTS. What are your experiences with this?