Created
June 16, 2014 20:46
-
-
Save jcoveney/7ccb8fdd085ed9a25ac9 to your computer and use it in GitHub Desktop.
Type projection and implicit resolution not playing nice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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