Supertype for scalaquery query

▼魔方 西西 提交于 2019-12-08 05:46:15

问题


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.


回答1:


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 of Projection[(Int,Int)]. Thus Query[Projection[Product]] is not a supertype of Query[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 }.



来源:https://stackoverflow.com/questions/6126076/supertype-for-scalaquery-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!