How can I specify the bounds of an unapplied higher order type parameter, such that the following compiles:
trait Declr[Impl[_]] // need to specify constraints for Impl's type parameter
trait Sys[S <: Sys[S]]
object X extends Declr[X] // doesn't compile, because S is more strict
trait X[S <: Sys[S]]
Without adding more type parameters to Declr
. Note that a solution is allowed to assume that the bound of Impl
's parameter is always S <: Sys[S]
(i.e that is the bound for any type that can go into Declr
).
I think I can write the constraint with a type member like this:
trait Declr {
type Impl[S <: Sys[S]]
}
object X extends Declr {
type Impl[S <: Sys[S]] = X[S]
}
trait X[S <: Sys[S]]
But how to do this as a type parameter (as the restatement of type Impl
is very noisy, and I want to have object X
as clean as possible)?
Why not