scalaquery 查询的超类型 [英] Supertype for scalaquery query

查看:50
本文介绍了scalaquery 查询的超类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有 Scalaquery 查询的超类型是什么?

What is the supertype for all Scalaquery queries?

据我所知,Query[Projection[Product]] 应该是它,例如:

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.* 应该适用于 Tab = new Table[(Int, Int)] {…}

……但显然我不明白在 Scala 中输入是如何工作的.

…but appearantly i don’t understand how typing in scala works.

我很困惑,所以如果我错过了什么,请询问.

I’m totally confused, so if i missed something, please ask.

推荐答案

这不起作用,因为 Projection 的类型参数是不变的,并且 Projection[Product] 需要协变才能是 Projection[(Int,Int)] 的超类型.因此,Query[Projection[Product]] 不是 Query[Projection[(Int,Int)]] 的超类型,这就是编译器抱怨的原因.

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.

一切都清楚了吗?如果没有,请在维基百科和 Scala 参考中阅读关于不变性和协变的内容.

Everything clear? If not, read about invariance and covariance in wikipedia and in the Scala reference.

X 的所有 Querys of Projections 的类型,其中 X 是 Product 的子类型,是 Query[Projection[X]] forSome { type X <: Product }.

The type of all Querys of Projections of X, where X is a subtype of Product, is Query[Projection[X]] forSome { type X <: Product }.

这篇关于scalaquery 查询的超类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆