Scala3 has support for "kind polymorphism". Docs also mention AnyKind type:
AnyKind plays a special role in Scala's subtype system: It is a supertype of all other types no matter what their kind is.
Question:
- can anyone give a working code example how
AnyKindgenerality is useful?
(surprisingly can't find any useful examples so far)
For example the type member
MirroredTypeofscala.deriving.Mirror.Product/Mirror.Sumis actually poly-kinded (although this is not written in the definition ofMirror/Mirror.Sum/Mirror.Product)https://docs.scala-lang.org/scala3/reference/contextual/derivation.html#mirror
The type member
MirroredMonoTypehas always kind*, including being existential (A[?]). ButMirroredTypecan be*or
* => *etc.
Notice that
MirroredElemTypesis also poly-kinded (MirroredElemTypes = (B, C),MirroredElemTypes[T] = (B, C), ...)So if I wanted to do something further with a tuple
MirroredElemTypesthen the only option would be to have upper boundAnyKindAnother example is
scala.quoted.Type(thanks to @Max for pointing this out)https://contributors.scala-lang.org/t/proposal-to-add-kind-polymorphism-to-the-language/2958/16
Miles Sabin. Adding kind-polymorphism to the Scala programming language https://www.youtube.com/watch?v=v6e7rYOXdcM