作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
函数中需要两个隐式,但我不能在相同的参数列表,因为我得到了 dependent method type
。所以我考虑再次柯里化(Currying),但这给了我一个语法错误。执行此操作的正确方法是什么?
def add[A](newAnnotations: Seq[A])
(implicit maybeAdd: MaybeAdd[L, Seq[A]])
(implicit mod: Modifier[maybeAdd.Out, Seq[A], Seq[A]]):
Slab[Content, maybeAdd.Out] = {
val l = maybeAdd(annotations, Seq[A]())
l.updateWith(_ ++ newAnnotations)
}
最佳答案
我编辑了 MaybeAdd
以具有 Aux
类型,正如@milessabin 所建议的那样。
def add[A, Out0](newAnnotations: Seq[A])(implicit maybeAdd: MaybeAdd.Aux[L, Seq[A], Out0], mod: Modifier[Out0, Seq[A], Seq[A]]): Slab[Content, mod.Out] = {
val l = maybeAdd(annotations, Seq[A]())
new Slab(content, mod(l, _ ++ newAnnotations))
}
关于scala - 类型依赖隐式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25988174/
我是一名优秀的程序员,十分优秀!