问题描述
考虑以下代码段中 --explain-types
的缩写输出
scala> :settings --explain-types
scala> def f[F[_ <: Int] <: List[_ <: Int],A <: Int](as: F[A]) = as
def f[F[_ <: Int] <: List[_ <: Int],A <: Int](as: F[A]): F[A]
scala> f(List(42))
...
List[A] <: List[_ <: Int]?
nothing <: A?
true
A <: Int?
false
List[_$1] = List[_$1]?
true
false
...
error: type mismatch;
found : List[Int]
required: F[A]
List[Int] <: F[A]?
false
我的解释是 List[A] <: List[_ <: Int]?
是错误的,因为
A <: Int?
false
但是在类型子句中是否给出了这种类型绑定
def f[...,A <: Int]
\______/
|
why is it not using this type bound?
当A <: Int
不满意时为什么不使用List[A] <: List[_ <: Int]?
然后尝试说?F := [A <: Int] =>> List[A]
?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)