0
무형의`Last` 유형 클래스를 탐색, 더 많거나 적은, shapeless
의 Last
의 Last
형 클래스 : 다음내가 밖으로 입력
import shapeless.{HList, HNil, ::}
trait Last[H <: HList] {
type Out
def last(in: H): Out
}
, 나는, 내가 이해, 유형 클래스 인스턴스의 개 입력 Last
HList
을 위해 : 그러나
object Last {
type Aux[L <: HList, O] = Last[L] { type Out = O }
// arrived at the truly `last` item, i.e. `H`
implicit def singleLast[H]: Aux[H :: HNil, H] = new Last[H :: HNil] {
override type Out = H
override def last(in: H :: HNil): H = in.head
}
// I believe this is the inductive step
implicit def hlistLast[H, T <: HList, OutT]
(implicit lt : Last.Aux[T, OutT]): Aux[H :: T, OutT] =
new Last[H :: T] {
type Out = OutT
def apply(l : H :: T): Out = lt(l.tail)
}
}
가 컴파일에 실패 왜 이해가 안 :
[error] /Users/kevinmeredith/Workspace/shapeless-sandbox/src/
main/scala/net/ops.scala:17: net.Last.Aux[T,OutT] does not take parameters
[error] def apply(l : H :: T): Out = lt(l.tail)
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
어떻게이 컴파일 타임 오류를 해결할 수 있습니까? 당신은 last
에 apply
을 변경
trait Last[H <: HList] {
type Out
def apply(in: H): Out
}
하지만 hlistLast
에 당신은 여전히 (그것을 정의하고 lt
에 그것을 사용하여 두) apply
를 사용하려고 : 같은
흠. 어떻게 해결할 수 있습니까? –
'hlistLast'에서'apply'를'last'로 이름을 바꾸거나'/ lastL '에서'apply'로 이름을 바꿉니다. –