scala - 如何在scala 3宏中匹配函数Expr
问题描述
使用 scala 3 引号语法:
'{...}
如何匹配函数表达式?
def macroImpl(expr: Expr[T => Any])(using q: Quotes): Expr[Any] = {
expr match {
case '{/*how to match function here*/} => ???
}
}
解决方案
一种方法是:
def macroImpl[T : Type](expr: Expr[T => Any])(using q: Quotes): Expr[Any] = {
expr match {
case '{(x : T) => ${body} : Any } => .... //do something
}
}
推荐阅读
- node.js - apache 和 node express 与 node rewrites
- java - Spring Boot 2.0 Web 应用程序不会启动嵌入式 servlet 容器
- vba - MSDataShape 错误,升级到 Windows 10 功能更新 1809 时损坏
- mysql - SQL 获取上一季度的记录,宽限期为 30 天
- .net - LUIS Intent 不返回带有空格的实体的全部值
- c# - 使用浏览器滚动条使 div 滚动
- javascript - 验证 ReduxForm:嵌套值
- vba - VBA 群发邮件问题
- c# - 加载页面时全部选中 GridView 行
- php - 在表单上传递选择多个