开发者

Supertype for scalaquery query

开发者 https://www.devze.com 2023-03-08 03:13 出处:网络
What is the supertype for all Scalaquery queries? As far as i have understood, Query[Projection[Product]] should be it, e.g.:

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]开发者_如何学Python] = 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.


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 }.

0

精彩评论

暂无评论...
验证码 换一张
取 消