Is it possible to access the type constructor parameter of a higher-kinded type in a context bound? I am looking to define a trait that takes a higher-kinded type, and has a method that returns an instance of the constructor parameter.
case class A[TContents](c: TContents) {
def foo = c
}
case class B[TContents](c: TContents) {
def foo = c
}
trait Fooable[TClass[_ <: TContents], TContents] {
def foo(obj: TClass[TContents]): TContents
}
case class AFooable[TContents] extends Fooable[A, TContents] {
def foo(obj: A[TContents]) = obj.foo
}
case class BFooable[TContents] extends Fooable[B, TContents] {
def foo(obj: B[TContents]) = obj.foo
}
class test {
def getFoo[TType[_] : Fooable, TContents](obj: TType[TContents]): TContents =
implicitly[Fooable[TType, TContents]].foo(obj)
implicit def aFooable = AFooable
val a = A(1)
val foo = getFoo(a)
}
This fails with compiler error complaining that context bounds cannot have two type parameters, but I cannot find another way to access the type constructor parameter?