Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 传递润滑油?_Scala_Shapeless - Fatal编程技术网

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)
    }
}