How to synthesize a higher-kinded type parameter? #20000
-
I need to synthesize polymorphic function with a higher-kinded type parameter, such as def fancyIdentity[F[_], A](fa: F[A]): F[A]
// or
val fancyIdentity: [F[_], A] => F[A] => F[A] How do I create type for such method/function? Note that /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */
type PolyType <: MethodOrPoly
val PolyType: PolyTypeModule
trait PolyTypeModule { this: PolyType.type =>
def apply(paramNames: List[String])(
paramBoundsExp: PolyType => List[TypeBounds], // How to specify the kind of F[_] as TypeBounds?
resultTypeExp: PolyType => TypeRepr
): PolyType
} However, when I print out the tree structure of a higher-kinded type parameter, I get back a I am using Scala 3.4.0. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To answer my own question: higher-kinds can be represented as For example, TypeBounds(
low = TypeRepr.of[Nothing],
hi = TypeLambda(
List("X"),
_ => List(TypeBounds.empty),
_ => TypeRepr.of[Any]
)
) are bounds of a type parameter The resulting |
Beta Was this translation helpful? Give feedback.
To answer my own question: higher-kinds can be represented as
TypeBounds
with an upper bound ofTypeLambda
.For example,
are bounds of a type parameter
F[_]
.The resulting
TypeBounds
can then be used in construction ofPolyType
.