tribbloid
tribbloid

Reputation: 3858

In Scala 3, what's the meaning of "unreducible application of higher-kinded type"?

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.

Upvotes: 2

Views: 85

Answers (0)

Related Questions