Given
trait Int // proper type
trait List[A] // 1st-order-kinded type constructor
trait Functor[F[_]] // higher-order-kinded type constructor taking type constructor
trait I[H[F[_]]] // higher-order-kinded type constructor taking higher-order type constructor that takes 1st-order type constructor
we cannot pass type argument of different kind as compared to the kind of declared type parameter
scala> def f[F[_[_[_]]]] = 42
def f[F[_$1]] => Int
scala> f[I]
val res5: Int = 42
scala> f[Functor]
1 |f[Functor]
| ^
| Type argument Functor does not conform to upper bound [_$1[_$2]] =>> Any
however we can declare the type parameter to be polymorphic in its kind via AnyKind
scala> def f[A <: AnyKind] = 42
def f[A <: AnyKind] => Int
scala> f[Int]
val res10: Int = 42
scala> f[List]
val res11: Int = 42
scala> f[Functor]
val res12: Int = 42
scala> f[I]
val res13: Int = 42
What is the use case of AnyKind
? What practical problem does it solve?
AnyKind
is to index types and type classes that are naturally kind polymorphic, such as Type in the Scala 3 quote/splice based metaprogramming facility. – Seligman