scalaquery 查询的超类型
所有 Scalaquery 查询的超类型是什么?
据我了解,Query[Projection[Product]]
应该是这样,例如:
Projection2[Int, Int]
<: Projection[Tuple2[Int,Int]]
<: Projection[Product]
所以val query: Query[Projection[Product]] = for (all <- Tab) yield all.*
应该适用于 Tab = new Table[(Int, Int)] {...}
...但显然我不明白在 scala 中输入是如何工作的。
我很困惑,所以如果我错过了什么,请询问。
What is the supertype for all Scalaquery queries?
As far as i have understood, Query[Projection[Product]]
should be it, e.g.:
Projection2[Int, Int]
<: Projection[Tuple2[Int,Int]]
<: Projection[Product]
so val query: Query[Projection[Product]] = for (all <- Tab) yield all.*
should work for Tab = new Table[(Int, Int)] {…}
…but appearantly i don’t understand how typing in scala works.
I’m totally confused, so if i missed something, please ask.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不起作用,因为 Projection 的类型参数是不变的,并且
Projection[Product]
需要协变才能成为Projection[(Int,Int)]
的超类型代码>.因此,Query[Projection[Product]]
不是Query[Projection[(Int,Int)]]
的超类型,这就是编译器抱怨的原因。一切都清楚了吗?如果没有,请阅读维基百科和 Scala 参考文献中有关不变性和协变性的内容。
X 的所有投影查询的类型(其中 X 是 Product 的子类型)为 Query[Projection[X]] forSome { type X <: Product }。
This doesn't work because the type parameter for Projection is invariant and it would need to be covariant for
Projection[Product]
to be a supertype ofProjection[(Int,Int)]
. ThusQuery[Projection[Product]]
is not a supertype ofQuery[Projection[(Int,Int)]]
, which is the reason why the compiler is complaining.Everything clear? If not, read about invariance and covariance in wikipedia and in the Scala reference.
The type of all Querys of Projections of X, where X is a subtype of Product, is
Query[Projection[X]] forSome { type X <: Product }
.