- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个类型 resultType
的 Context.this.type#c#universe#Type
.我需要将它与 Unit
匹配类型。我试过
resultType match {
case q"Unit" => ...
}
Unit
这里只是一个字符串文字,显然不匹配。如何通过 quasiqotes 匹配类型?
resultType match {
case TypeRef(ThisType(_), Symbol("scala.Unit"), _) => ...
}
[error] pattern type is incompatible with expected type;
[error] found : Symbol
[error] required: Context.this.c.universe.SymbolContextApi
最佳答案
在这种情况下,quasiquotes 不起作用的主要原因是您在 Tree
上不匹配。而是一个 Type
.这两个是反射 API 的独立概念,并不完全相同。
检查类型是否与您期望的相同的一种简单方法是使用 typeOf
并输入相等运算符 =:=
:
case tpe if tpe =:= typeOf[Unit] =>
TypeRef
匹配并检查其中的符号是否相等,如其他答案所示。
关于scala - 如何通过 quasiquotes 或 deconstructors 匹配 `universe#Type`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18735295/
Quasiquotes 的 Scala 文档在解释 Lifting 时提到了这一点: One can also combine lifting and unquote splicing: scala
我刚刚开始学习 Scala 编译时反射,并且通过 Scala 官方指南向我介绍了 quasiquotes。 我仍在努力解决的一个概念是,如果我想为已定义的对象生成 AST,我应该如何使用 quasiq
我想用 Haskell 写一个引用。需要将 name 参数传递给 gen 函数以生成声明。 quote :: String -> QuasiQuoter quote name = QuasiQuot
不幸的是,最直观的方式, val world = "Earth" val tree = q"""println("Hello $world")""" 结果 Error:(16, 36) Don't k
我正在尝试将 OverloadedLabels 与 here 包中的 QuasiQuotes 一起使用。使用普通镜头可以,但 #foo 在编译期间因解析错误而失败。 field @"foo" 也是如此
我正在尝试在 R 中编写一个函数,根据分组变量汇总数据框。分组变量作为列表给出并传递给 group_by_at ,我想对它们进行参数化。 我现在正在做的是: library(tidyverse) d
documentation对于模板 Haskell 说 QuasiQuoter 被定义为 data QuasiQuoter = QuasiQuoter { quoteExp :: String ->
我正在使用 macroparadise 2.0.0-M3 在 Scala 2.10.3 中试验宏注释。我试图了解如何使用 quasiquotes 为带注释的类生成伴随对象。到目前为止,我发现的是如何在
通读Why It’s Nice to be Quoted ,在第 3 节中有一个在准引号中拼接变量标识符的示例。 subst [:lam | $exp:e1 $exp:e2 |] x y =
我正在尝试实现一个隐式实现器,如下所述:http://docs.scala-lang.org/overviews/macros/implicits.html 我决定创建一个宏,该宏使用准引号将案例类与
我正在尝试使用 Scala 从 quasiquote 内部调用 Shapeless 宏,但没有得到我想要的结果得到。 我的宏不返回任何错误,但它不会将 Witness(fieldName) 扩展为 W
我正在尝试使用 scala-pickling在my project之一秒。我试过 mimic macroid 的构建文件这似乎也使用酸洗,但我在 sbt test 上不断收到此错误: [error]
这是我面临的问题的简化版本,但潜在的问题仍然存在。 调用宏后,我想动态生成案例类。我能够从宏调用等中检索参数。我遇到的问题是尝试在 quasiquotes 中使用字符串变量。我基本上想要以下内容: d
我怎样才能像这样插值: {-# LANGUAGE QuasiQuotes #-} import Text.RawString.QQ myText :: Text -> Text myText myVa
我很好奇为什么 purrr::map_*函数家族,尽管是 tidyverse 的一部分, 不支持通过拼接取消引用其 dots 的准引用在评估映射函数之前? library(tidyverse) lib
这个问题的动机与我的 previous question 相似(尽管这是关于我在 different context 中遇到的问题)。 我可以很容易地对函数文字进行模式匹配,而无需 quasiquot
我正在尝试搜索数据库,然后使用源自原始搜索的名称标记输出,"derived_name"在下面的可重现示例中。我正在使用 dplyr管道 %>% ,并且我在准报价和/或非标准评估方面遇到了麻烦。具体来说
背景 : 我正在研究哈姆雷特是如何工作的,有 WAI,但没有 Yesod。我没有掌握模板 Haskell,但在我深入研究它之前,我想知道是否有一个已知/快速的解决方案来完成这项任务。 规范 : 我想知
haskellwiki 中所述的准报价主要显示为在 Haskell 中嵌入其他语言的有用工具,而不会弄乱字符串引用。 问题是:对于 Haskell 本身,将现有的 Haskell 代码放入一个 qua
我正在尝试编写一个自定义函数,我使用 rlang的准报价。此函数也在内部使用 dplyr的 join职能。我在下面提供了一个最小的工作示例来说明我的问题。 # needed libraries lib
我是一名优秀的程序员,十分优秀!