Implicit conversion on type alias does not seem to work ont his code
trait TriIndexable[M[_,_,_,_]] {
def get[A,B,C,D](m: M[A,B,C,D])(a: A, b: B, c: C): Unit
}
implicit object TriMapTriIndexable extends TriIndexable[TriMap] {
def get[A,B,C,D](m: TriMap[A,B,C,D])(a: A, b: B, c: C): Unit = {
println("Tri indexable get")
}
}
type TriIntMap[D] = TriMap[Int,Int,Int,D]
trait TupleIntIndexable[M[_]] {
def get[D](m: M[D])(a: (Int, Int, Int)): Unit
}
implicit object TriIntMapTupleIntIndexable extends TupleIntIndexable[TriIntMap] {
def get[D](m: TriIntMap[D])(a: (Int, Int, Int)): Unit = {
println("Tri Int indexable get")
}
}
class TriMap[A,B,C,D]() {
}
implicit class TriIndexableOps[A,B,C,D,M[_,_,_,_]](
val tri: M[A,B,C,D]
)(implicit ev: TriIndexable[M]) {
def get(a: A, b: B, c: C) = {
ev.get(tri)(a,b,c)
}
}
implicit class TupleIntIndexableOps[D,M[_]](
val tri: M[D]
)(implicit ev: TupleIntIndexable[M]) {
def get(a: (Int,Int,Int)) = {
ev.get(tri)(a)
}
}
val test: TriIntMap[String] = new TriMap[Int,Int,Int,String]()
test.get(5,5,5)
test.get((5,5,5))
Why does this error on the last line? I'm trying to give a subset of TriMaps the ability to index with another object, in this case it's a tuple of three ints. How can I fix this?
https://scastie.scala-lang.org/pMEa7Zq6TLeBxq1k9zG1oA
from Recent Questions - Stack Overflow https://ift.tt/3yKljvf
https://ift.tt/eA8V8J
Comments
Post a Comment