I want to do the following stuff using Scala's context-bound pattern:
class Polynomial[T: Ring] {
def apply[X: Ring with Includes[T]](x: X): X = ...
...
}
This is a polynomial class which requires the coefficients are elements in a Ring T
. When applying this polynomial to a element (evaluation), the type of the parameter x
is required to be a ring, and elements of type T
can be implicitly cast to type X
. for example T = Double, X = SquareMatrix
.
How can I impose more than one type constraints to a generic type parameter in Scala?