【发布时间】:2015-10-30 09:40:47
【问题描述】:
我正在尝试在 scala 中执行此操作
abstract class Rel[A: NeoNode, B: NeoNode] {
val from: A
val to: B
}
abstract class NeoRel[C <: Rel[A, B] : Mapper, A: NeoNode, B: NeoNode]{
def save(c: C)
}
class NeoRelOperations[C <: Rel[A, B] : ({type L[x <: Rel[A, B]] = NeoRel[x, A, B]})#L : Mapper, A: NeoNode, B: NeoNode](c: C) {
val neoRel = implicitly[NeoRel[C, B, A]]
def save() = neoRel.save(c)
}
object NeoRelOperations {
def apply[C <: Rel[A, B] : ({type L[x <: Rel[A, B]] = NeoRel[x, A, B]})#L : Mapper, A: NeoNode, B: NeoNode](c: C) = new NeoRelOperations(c)
}
但我对隐式有问题:
val neoRel = implicitly[NeoRel[C, B, A]]
我在编译器上得到了这个
Error:(88, 26) could not find implicit value for parameter e: com.kreattiewe.neo4s.orm.NeoRel[C,B,A]
val neoRel = implicitly[NeoRel[C, B, A]]
^
Error:(88, 26) not enough arguments for method implicitly: (implicit e: com.kreattiewe.neo4s.orm.NeoRel[C,B,A])com.kreattiewe.neo4s.orm.NeoRel[C,B,A].
Unspecified value parameter e.
val neoRel = implicitly[NeoRel[C, B, A]]
^
Error:(99, 119) inferred type arguments [C,Nothing,Nothing] do not conform to class NeoRelOperations's type parameter bounds [C <: com.kreattiewe.neo4s.orm.Rel[A,B],A,B]
def apply[C <: Rel[A, B] : ({type L[x <: Rel[A, B]] = NeoRel[x, A, B]})#L : Mapper, A: NeoNode, B: NeoNode](c: C) = new NeoRelOperations(c)
^
Error:(99, 140) type mismatch;
found : C(in method apply)
required: C(in class NeoRelOperations)
def apply[C <: Rel[A, B] : ({type L[x <: Rel[A, B]] = NeoRel[x, A, B]})#L : Mapper, A: NeoNode, B: NeoNode](c: C) = new NeoRelOperations(c)
^
Error:(99, 119) could not find implicit value for evidence parameter of type com.kreattiewe.neo4s.orm.NeoRel[C,A,B]
def apply[C <: Rel[A, B] : ({type L[x <: Rel[A, B]] = NeoRel[x, A, B]})#L : Mapper, A: NeoNode, B: NeoNode](c: C) = new NeoRelOperations(c)
上下文绑定处理可能有另一种解决方案
【问题讨论】:
-
你能提供一个完整的工作示例吗?
-
@TravisBrown 顺便说一句,即使有空特征(我试过)也会出现同样的错误:
trait Mapper[T]和trait NeoNode[T] -
@DaunnC 啊,谢谢-我超级懒惰,没有尝试过。我稍后再看看。
标签: scala functional-programming