-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
import language.higherKinds
object Main {
trait Eq[A]
case class Cofree[S[_], A](head: A, tail: Cofree[S, A]) //simplified
implicit val intEq: Eq[Int] = null
implicit def forList[A : Eq]: Eq[List[A]] = ???
implicit def eqCofree[S[_], A : Eq](implicit
S: implicit Eq[A] => Eq[S[A]]): Eq[Cofree[S, A]] = ???
val a = eqCofree[List, Int]
}This fails with:
-- Error: /tmp/scastie6251223766744740367/src/main/scala/main.scala:16:29 ------
16 | val a = eqCofree[List, Int]
| ^
|no implicit argument of type implicit Main.Eq[Int] => Main.Eq[List[Int]] was found for parameter S of method eqCofree in object Main.
|I found:
|
| {
| def $anonfun(implicit evidence$4: Main.Eq[Int]): Main.Eq[List[Int]] =
| {
| def $anonfun(evidence$1: Main.Eq[Any]): Main.Eq[List[Any]] =
| Main.forList[Any](evidence$1)
| closure($anonfun)
| }
| closure($anonfun)
| }
|
|But method forList in object Main does not match type implicit Main.Eq[Int] => Main.Eq[List[Int]]
but if you use eqCofree(intEq, forList), it compiles.