scala - Scala 3 TypeRepr 匹配更高种类的类型
问题描述
我如何正确地模式匹配TypeRepr
更高种类的类型?Existentials 成功匹配类,但是当我尝试使用类型时,我得到编译器错误unreducible application of higher-kinded type writetype.Foo to wildcard arguments
import scala.quoted.*
type Foo[X]
class Bar[X]
inline def writeType[T]: String = ${writeTypeImpl[T]}
def writeTypeImpl[T](using Type[T], Quotes): Expr[String] =
import quotes.reflect.*
val tpe = TypeRepr.of[T]
val s = tpe.asType match
//case '[Foo[?]] => "FooSuccess"
case '[Bar[?]] => "BarSuccess"
case _ => "Fail"
Expr(s)
解决方案
这是您需要的答案:
您必须使用 a trait
or abstract class
or Foo[A]
where 是具体类型(或类型参数)
推荐阅读
- node.js - 如何使用 mongoose 从 mongo db 中找到所有不等于 id 数组的对象?
- r - 将数据帧从一个第一个转换为另一个
- laravel - 为 Eloquent Laravel 5.7 的 whereMonth 订购一天?
- amazon-web-services - 是否可以在没有运行 EC2 实例的情况下运行 Terrafrom/Ansible 脚本?
- cors - CorsHttpHandler 是否支持通配符以允许任何域?
- c - 动态库文件的全局变量加载到哪里?
- twilio - 如何使 VoiceResponse 中 TwiML 重定向的端点命中返回 MessagingResponse?
- python - 如果用户最后这么说,如何让脚本自行重启?
- dijkstra - 有人在 OPL 中使用过 Dijkstra 算法吗?
- ada - 无法在 GNAT 2019 社区版的 microbit 上获得 Ada 滚动文本演示