Scala Generic type and subtyping

77 Views Asked by At
abstract class Dog[+T,-U,V] {
    def bark[A >: Dog[T,Dog[U,T,V],Dog[V,V,V]], B <: Dog[U,T,V]](
    stranger: A,
    listener: (Dog[U,T,A]=>B)=>B
    ): Dog[Dog[T,U,V], T=>U, B]
}

This is one of the problem on my homework, which totally confused me. The question asked if compiler will report an error. I understand how covariant and contravariant work with single type.

Here is my thought of the problem, if wrong please correct me.

def bark[A >: Dog[T,Dog[U,T,V],Dog[V,V,V]], B <: Dog[U,T,V]]

this line both A and B are type parameter position, and should flip, and B should be B >: Dog[U,T,V], but for other part of the program, I have no clue what's going on.

0

There are 0 best solutions below