Search code examples
scalapolymorphismimplicits

Context bound for nested type


Is it possible to create somehow a context bound for a nested type? Something like this:

def f[T : U[List]](a: T)

Ofc, this is not Scala syntax, but illustrates what I want to achieve, that is, get a bound on an implicit U[List[T]]. Is this possible?

Thanks.


Solution

  • You could do it with type alias:

    type UList[X] = U[List[X]]
    def f[T : UList](a: T)
    

    or

    def f[T:({type UL[X] = U[List[X]]})#UL](a: T)