6

我正在尝试在 N 处拆分大小为 S 的列表,其中已知 N,M 总和为 S。这不会编译:

def splitIt[N <: Nat,
            M <: Nat,
            S <: Nat](u: Sized[List[Int], N] {type A = N},
                      v: Sized[List[Int], M] {type A = M},
                      t: Sized[List[Int], S] {type A = S})(implicit sum: SumAux[N, M, S]): Unit = {
  val z = t.splitAt[N]
}

错误

No implicit view available from List[Int] => scala.collection.GenTraversableLike[S,List[Int]].

not enough arguments for method sizedOps: (implicit evidence$2: List[Int] => scala.collection.GenTraversableLike[S,List[Int]])shapeless.SizedOps[S,List[Int],S]. Unspecified value parameter evidence$2.

最终正确版本

def splitIt[N <: Nat,
            M <: Nat, S <: Nat](u: Sized[List[Int], N] {type A = Int},
                                v: Sized[List[Int], M] {type A = Int},
                                t: Sized[List[Int], S] {type A = Int})(implicit sum: DiffAux[S, N, M], toInt: ToInt[N]): Unit = {
  val z = t.splitAt[N]
}
4

1 回答 1

5

type A需要是list 元素的类型,而不是 size 参数。这就是为什么它试图转换为GenTraversableLike[A, List[Int]]. 您需要在每种情况下设置A为。Int

于 2012-12-24T14:04:32.990 回答