Skip to content

Instantly share code, notes, and snippets.

@drdozer
Created February 15, 2017 13:22
Show Gist options
  • Save drdozer/1812766d0c625e58995997025414feb0 to your computer and use it in GitHub Desktop.
Save drdozer/1812766d0c625e58995997025414feb0 to your computer and use it in GitHub Desktop.
import cats.Id
import cats.data.{Const, Prod}
/**
*
*
* @author Matthew Pocock
*/
object TestImplicitProblem {
def main(args: Array[String]): Unit = {
trait MyTypeclass[R[_]]
implicit object StringImpl extends MyTypeclass[Const[String, ?]]
implicit object IdImpl extends MyTypeclass[Id]
implicit def productImpl[R1[_], R2[_]](implicit R1: MyTypeclass[R1], R2: MyTypeclass[R2])
: MyTypeclass[Prod[R1, R2, ?]] = new MyTypeclass[Prod[R1, R2, ?]] {}
// finds this
type si[T] = Const[String, T]
val psiTpe = implicitly[MyTypeclass[si]]
// finds both of these
val si = implicitly[MyTypeclass[Const[String, ?]]]
val idI = implicitly[MyTypeclass[Id]]
// can't find this
val psi = implicitly[MyTypeclass[Prod[Id, Const[String, ?], ?]]]
// can't find this
type psiT[T] = Prod[Id, Const[String, ?], T]
val psiT = implicitly[MyTypeclass[psiT]]
// nor this
val psiPTpe = implicitly[MyTypeclass[Prod[Id, si, ?]]]
// but can find this
type psiTTpe[T] = Prod[Id, si, T]
val psiTTpe = implicitly[MyTypeclass[psiTTpe]]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment