The particular reason for wanting to do this is to still be able to use pattern matching against a value from a super-class. For instance, I'd like to be able to match with case None
when looking at values of type Option[Throwable]
, but this doesn't seem to be possible since Throwable
does not, and never will (I imagine) have a CanEqual
instance.
Besides greatly improved type inference, the Scala 3 type system also offers many new features, giving you powerful tools to statically express invariants in the types: Enumerations. Enums have been redesigned to blend well with case classes and form the new standard to express algebraic data types. Opaque Types.
The answer is: it doesn't matter! We can already use Scala 3 to build Spark applications thanks to the compatibility between Scala 2.13 and Scala 3.
Scala runs on the Java platform (Java virtual machine) and is compatible with existing Java programs.
At a high level, Scala shares these similarities with JavaScript: Both are considered high-level programming languages, where you don't have to concern yourself with low-level concepts like pointers and manual memory management. Both have a relatively simple, concise syntax.
Try limiting the scope of givens like so
val x: Option[Throwable] = None
{
given CanEqual[Option[Throwable], Option[Throwable]] = CanEqual.derived
x match {
case Some(v) => v
case None => new Throwable()
}
} // after this brace CanEqual given is out-of-scope
x match {
case Some(v) => v
case None => new Throwable()
} // compile-time error: Values of types object None and Option[Throwable] cannot be compared with == or !=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With