Scala Zipwith产品实现与成型?

Scala Zipwith产品实现与成型?,scala,shapeless,Scala,Shapeless,鉴于: //给定一个大小为N的HList,提供HList之和的证据 //乘以3(长度):2(长度):1(长度):HNil //示例:输入:_1::_2::_2->输出:_3+_4+_2::HNil trait HListProductZipped[L您缺少hnilHListProductZipped返回类型中的细化,这意味着编译器无法知道它的Out是HNil。将其更改为Aux[HNil,HNil]将使这项工作正常。事实上,我刚刚发现了问题所在。但是,也许这个问题值得一提,所以如果没有人回答,我会

鉴于:

//给定一个大小为N的HList,提供HList之和的证据
//乘以3(长度):2(长度):1(长度):HNil
//示例:输入:_1::_2::_2->输出:_3+_4+_2::HNil

trait HListProductZipped[L您缺少
hnilHListProductZipped
返回类型中的细化,这意味着编译器无法知道它的
Out
HNil
。将其更改为
Aux[HNil,HNil]
将使这项工作正常。

事实上,我刚刚发现了问题所在。但是,也许这个问题值得一提,所以如果没有人回答,我会在一天后回答。哦,刚刚看到你的评论。)
// Given an HList of size N, provide evidence of the sum of HList
// multiplied by _3 (length) :: _2 (length) :: _1 (length) :: HNil
// Example: input: _1 :: _2 :: _2 -> output: _3 + _4 + _2 :: HNil
trait HListProductZipped[L <: HList] {
  type Out <: HList
}
object HListProductZipped {

  type Aux[L <: HList, Out1 <: HList] = HListProductZipped[L] { type Out = Out1 }

  def apply[L <: HList](implicit ev: HListProductZipped[L]): Aux[L, ev.Out] = ev

  implicit def induct[H <: Nat, T <: HList, L <: Nat](
    implicit ev: Length.Aux[H :: T, L],
             prod: Prod[H, L],
             rest: HListProductZipped[T]
  ): HListProductZipped.Aux[H :: T, prod.Out :: rest.Out] = new HListProductZipped[H :: T] {
    type Out = prod.Out :: rest.Out
  }

  implicit val hnilHListProductZipped: HListProductZipped[HNil] = new 
    HListProductZipped[HNil] {
      type Out = HNil
    }

}
import shapeless._
import nat._
import net.HListProductZipped

scala> val a = HListProductZipped[_1 :: _2 :: HNil]
a: net.HListProductZipped[shapeless.::[shapeless.Succ[shapeless._0],shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],shapeless.HNil]]]{type Out = shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],net.HListProductZipped.hnilHListProductZipped.Out]]} = net.HListProductZipped$$anon$3@130efbff

scala> val e: a.Out = _2 :: _2 :: HNil
<console>:19: error: type mismatch;
 found   : shapeless.::[shapeless.nat._2,shapeless.::[shapeless.nat._2,shapeless.HNil]]
    (which expands to)  shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],shapeless.HNil]]
 required: a.Out
    (which expands to)  shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],shapeless.::[shapeless.Succ[shapeless.Succ[shapeless._0]],net.HListProductZipped.hnilHListProductZipped.Out]]
       val e: a.Out = _2 :: _2 :: HNil
                         ^