我或多或少地输入了shapeless的Last的Last类型类
import shapeless.{HList, HNil, ::}
trait Last[H <: HList] {
type Out
def last(in: H): Out
}然后,据我所知,我键入了HList的Last类实例
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我如何修复这个编译时错误?
发布于 2017-01-16 11:47:58
Last的实际非成形实现如下所示:
trait Last[H <: HList] {
type Out
def apply(in: H): Out
}您将apply更改为last,但在hlistLast中您仍在尝试使用apply (通过定义它并在lt上使用它):
def apply(l : H :: T): Out = lt(l.tail)编译器错误来自于试图在lt.apply不存在的情况下使用它。在这种情况下,如果编译器首先告诉您last未实现,会更有帮助。
https://stackoverflow.com/questions/41666832
复制相似问题