This code does what you are asking but I don't think you mean to do that:
trait A[B[_]]
trait Base {
type AImpl <: A[B] forSome { type B[_] }
def foo: AImpl
}
if you can be more specific I can probably pinpoint your problem and suggest another way of doing so.
As I previously insisted, there are many problems in your intention. It's very clear to me that you are trying to do something you are not supposed to.
To explain a couple issue, you first need to understand existential types. Here, you are quantifying AImpl with certain constraint:
type AImpl <: A[B] forSome { type B[_] }
This asks its realization to comply to such type. However, this type cannot possibly have any realization, because of
B is hidden inside of existential type, therefore it's unknown outside;
A is invariant, so it forces realization to be subtype of A[B] for that exact hidden B.
these two together forbids AImpl from realizing. The way to fix it is to turn A covariant:
trait A[+B[_]]
trait Base {
type AImpl <: A[B] forSome { type B[_] }
def foo: AImpl
}
trait BB[T]
trait AA extends A[BB]
object Child extends Base {
override type AImpl = A[BB]
def foo = ???
}
this code compiles with no problem.
However, again, I have to say existentially quantifying B is a fundamentally flawed idea, because in the given environment, there is no type safe way to recover B anymore, if you ever need it, not to mention higher kinded types in scala is insufficient and malformed.
AImplhigher kinded.