6
Sto cercando di dividere un elenco di taglia S a N, dove è noto che N, M somma fino a S. Questo non può essere compilato:Come splitAt una lista scala utilizzando informe
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]
}
errori
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.
finale versione corretta
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]
}
+1, ma questo è solo il primo passo: conoscere SumAux [N, M, S] 'non ti dà il' Diff [S, N] 'devi dividere la lista (sfortunatamente), e dovrete anche aggiungere un 'ToInt' per' N'. –
Modificato il 'A's e aggiunto un implicito' toInt'. Come aggiungere il 'Diff'? – Peteris
@Peteris: è possibile rimuovere 'SumAux' (a meno che non sia necessario per qualche altro motivo nel proprio codice reale) e aggiungere 'Diff [S, N]' o 'DiffAux [S, N, M]'. –