<: Type : Type, what does this mean?
Scala combines both object-oriented concepts with functional programming concepts. For example, in Scala type parameters can be constrained using both subtyping constraints as well as type class constraints
T <: Data // subtyping contraint on T
T : Arithmetic // type class constraint on T
T <: Data : Arithmetic // subtyping and type class contraint on T
In both cases the point of these compile-time constraints is to tell compiler what capabilities type parameter T
provides, that is, what methods we can call on values of type T
. Deciding what kinds of constraints to put on your type parameters is a design decision. Some programers like pure functional programming approach of parametric polymorphism with type classes, others prefer more object-oriented subtyping approach, and some argue that we still have not explored the true power of the mixed approach Scala provides. Either way Scala does not make the decision for you. As a side note, subtyping polymorphism is discouraged or completely removed in some languages such as Rust.