gpt4 book ai didi

scala - 类型依赖隐式

转载 作者:行者123 更新时间:2023-12-05 06:45:07 24 4
gpt4 key购买 nike

函数中需要两个隐式,但我不能在相同的参数列表,因为我得到了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com