Skip to content

Instantly share code, notes, and snippets.

@jcoveney
Created June 16, 2014 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcoveney/7ccb8fdd085ed9a25ac9 to your computer and use it in GitHub Desktop.
Save jcoveney/7ccb8fdd085ed9a25ac9 to your computer and use it in GitHub Desktop.
Type projection and implicit resolution not playing nice
trait Plat[P <: Plat[P]] {
type Keyed[_, _]
}
class MPlat extends Plat[MPlat] {
type Keyed[K, V] = (K, TraversableOnce[V])
}
trait Prod[P <: Plat[P], T, This <: Prod[P, T, This]] {
def name(str: String)(implicit wrap: Wrapper[P, T, This]): This = wrap(this)
}
trait KProd[P <: Plat[P], K, V] extends Prod[P, P#Keyed[K, V], KProd[P, K, V]]
object Wrapper {
implicit def keyedWrapper[P <: Plat[P], K, V]: Wrapper[P, P#Keyed[K, V], KProd[P, K, V]] =
new Wrapper[P, P#Keyed[K, V], KProd[P, K, V]] {
override def apply(p: Prod[P, P#Keyed[K, V], KProd[P, K, V]]): KProd[P, K, V] = throw new Exception("we made it!")
}
}
sealed trait Wrapper[P <: Plat[P], T, This <: Prod[P, T, This]] {
def apply(p: Prod[P, T, This]): This
}
// The following fails, I want it to be able to get the implicit which works
(new Prod[MPlat, (Int, TraversableOnce[Int]), KProd[MPlat, Int, Int]] { }).name("hey")
// this is proof that the implicit is in scope and works on the given type, it's just not being found
keyedWrapper[MPlat, Int, Int](new Prod[MPlat, (Int, TraversableOnce[Int]), KProd[MPlat, Int, Int]] { })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment