更高种类类型缺失的清单
我在 scalac 中遇到问题,找不到我想要使用的更高级内部类型的清单。考虑一些带有构造函数的类似列表的类型:
trait L[S, A]
def emptyList[S, A: Manifest]: L[S, A] = ???
现在另一种类型从它的伴生对象构造出来,如下所示:
object Tree {
private class Leaf[S, A]
private class Impl[S, A](l: L[S, Leaf[S, A]]) extends Tree[S, A]
def empty[S, A]: Tree[S, A] = new Impl(emptyList[S, Leaf[S, A]])
}
trait Tree[S, A]
它失败了,因为 scalac 想要类型 Leaf[S, A]
的清单。为什么不可用?我不想通过要求传递清单参数来放松 Leaf
的可见性并弄乱构造函数。
我完全不明白这一点——我认为从 JVM 的角度来看,在 L
中构造的数组可以归结为 Array[Leaf[_, _]]
又名 Array[java.lang.Object]
,那么这个拒绝有什么意义呢?
有什么办法可以找到清单吗?
I am having trouble with scalac not finding a manifest for a higher-kinded internal type I want to use. Consider some list like type with a constructor:
trait L[S, A]
def emptyList[S, A: Manifest]: L[S, A] = ???
Now another type which gets constructed from its companion object like this:
object Tree {
private class Leaf[S, A]
private class Impl[S, A](l: L[S, Leaf[S, A]]) extends Tree[S, A]
def empty[S, A]: Tree[S, A] = new Impl(emptyList[S, Leaf[S, A]])
}
trait Tree[S, A]
It fails because scalac wants a manifest for type Leaf[S, A]
. Why isn't that available? I don't want to relax visibility of Leaf
and clutter the constructor by asking to pass in a manifest argument.
I don't understand this at all—I thought that from the JVM perspective, the arrays that are constructed in L
boil down to Array[Leaf[_, _]]
aka Array[java.lang.Object]
, so what's the point of this refusal?
Any ways to find the manifest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为所有参数提供清单,实际上创建一个完整的清单链:
You have to provide manifest for all your parameters, in effect creating a complete manifest chain: