admin管理员组文章数量:1334133
Here is a short example:
object ErrorCase {
type K[T] = T => Seq[T]
type KI = K[? >: Nothing <: Int]
// not working
/*
unreducible application of higher-kinded type [T] =>> T => Seq[T] to wildcard arguments
Explanation
===========
An abstract type constructor cannot be applied to wildcard arguments.
Such applications are equivalent to existential types, which are not
supported in Scala 3.
*/
type KI2 = (? >: Nothing <: Int) => Seq[? >: Nothing <: Int] // works despite equivalent
}
this explanation is not suitable enough, as K[T]
is a very concrete type constructor that can be resolved immediately, not an abstract type constructor
What's the cause of this error? Is it a compiler bug?
UPDATE 1, Obviously the bound ? >: Nothing <: Int
is quite useless in practice, but similar definition may be frequently encountered in refining polymorphic function to a normal function, e.g. the following definition:
type KI = K[? >: Tuple2[?,?] <: Product]
can be normalised to (using the variance/monotonicity of function definition (-I) => (+O)
):
= (? >: Tuple[?,?] <: Product) => Seq[? >: Tuple[?,?] <: Product]
= Tuple[?,?] => Seq[Product]
which is very normal. It can even be inlined for both concrete & abstract K[T]
, but that's a different augmentation.
本文标签:
版权声明:本文标题:In Scala 3, what's the meaning of "unreducible application of higher-kinded type"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736241871a1917107.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论