Scala 传递润滑油?
在它编译的代码段中需要更改什么Scala 传递润滑油?,scala,shapeless,Scala,Shapeless,在它编译的代码段中需要更改什么 import shapeless._ import LUBConstraint._ import ops.hlist.Prepend class Foo[L <: HList: <<:[Int]#λ](val l: L) { def ++[H <: HList: <<:[Int]#λ](h: H)(implicit prepend: Prepend[L, H]) = { new Foo(l ::: h) } }
import shapeless._
import LUBConstraint._
import ops.hlist.Prepend
class Foo[L <: HList: <<:[Int]#λ](val l: L) {
def ++[H <: HList: <<:[Int]#λ](h: H)(implicit prepend: Prepend[L, H]) = {
new Foo(l ::: h)
}
}
好问题。。。你非常接近:-) 问题是,尽管Scala编译器对我们来说很明显,但它无法推断
Int
元素的两个HLists
的串联是HList
的Int
元素。我们可以通过将串联的类型拉入类型变量(out
,注意使用Prepend.Aux
类型别名来约束这个新的类型变量),然后要求它直接证明out
具有所需的属性(通过要求提供out
形状的证据)
导入无形状_
导入ops.hlist.Prepend
导入约束_
Foo类[L我无法运行此程序,Scala找不到必要的前置词:这就是问题所在,所以…答案过时了:-(我已将其更新为现在时。非常感谢Miles!这是我的不成形拼图中缺少的一块:D
could not find implicit value for evidence parameter of type shapeless.LUBConstraint[prepend.Out,Int]
import shapeless._
import ops.hlist.Prepend
import LUBConstraint._
class Foo[L <: HList: <<:[Int]#λ](val l: L) {
def ++[H <: HList: <<:[Int]#λ, Out <: HList](h: H)
(implicit prepend: Prepend.Aux[L, H, Out], ev: LUBConstraint[Out, Int]) = {
new Foo(l ::: h)
}
}