I can define this:
def test[V[X]](c:Ctx[_,V]) {}
And it seems to work fine with the output type:
scala> trait Ctx[ C, V[ _ ]] defined trait Ctx scala> def test[V[X]](c:Ctx[_,V]) {} test: [V[X]](c: Ctx[_, V])Unit scala> class P extends Ctx[Int, List] defined class P scala> new P res0: P = P@1f49969 scala> test(res0)
Change I suspect that replacing the Ctx tag Ctx not practical to use an abstract type, but this is what I was able to do:
trait Ctx[C] { type V[X] } class CtxOption[C] extends Ctx[C] { type V[X] = Option[X] } class CtxList[C] extends Ctx[C] { type V[X] = List[X] } def test(ctx:Ctx[_]) { println(ctx) } val ctxOptInt = new CtxOption[Int] val ctxListStr = new CtxList[String] test(ctxOptInt) test(ctxListStr) val list = collection.mutable.ListBuffer[Ctx[_]]() list += ctxOptInt list += ctxListStr list
Using an abstract type for V-parts is a difficult (or impossible) task to determine the type parameter syntax for a wildcard type constructor. In addition, as shown in the ListBuffer example, you can handle objects where V is another type constructor (option and list in my example). The first solution I provided will not allow you to do this.
Edit 2 : How about?
trait AbstractCtx[C] { type W[X] } trait Ctx[C,V[_]] extends AbstractCtx[C] { type W[X] = V[X] } def test(ctx:AbstractCtx[_]) { println(ctx) }
huynhjl
source share