I am trying to have a method return a value that must implement a typeclass, and I think it is highlighting to me more generally how I don't understand Scala's generic parameter resolution process. I have a situation something like this:
trait IsContainer[A, T] {
def getOtherContainer[O](implicit tc2: IsUnit[O]): O
}
trait IsUnit[A] { }
implicit val anIntIsUnit = new IsUnit[Int] { }
implicit def aListIsContainer[T] = new IsContainer[List[T], T] {
def getOtherContainer[Int] = 3
}
This is raising a compile error: Missing implementation for: def getOtherContainer. My uninformed guess about what should be happening here is that Scala sees I have passed the generic parameter O, and considers the method implemented if all instances of the O type are consistent. So in this case (since I have explicitly told it that O = Int, it checks that there is an instance of IsUnit[Int] in scope, and that the output type of the method is of type O. If this is correct (and I'm not saying it is!) then why is this not working?
More generally, if I skipped the [O] generic parameter and let it guess - so I just implemented the method with getOtherContainer = 3 - should I also expect it work? To infer what O should be, does it scan over the line and see if O has been concretely filled out in any of the three places it is mentioned, and infer from that?
Thanks!