我所知道的TypeTags就是他们以某种方式取代了Manifest.互联网上的信息很少,并没有让我对这个主题有很好的认识.
所以,如果有人在TypeTag上分享了一些有用的资料,包括例子和流行的用例,我会很高兴.我们也欢迎详细的解答和解释.
在哪里我可以学习如何构建Scala的宏生成的AST?
Scaladoc不像我想的那样有用.例如:
abstract def Apply(sym: Universe.Symbol, args: Universe.Tree*): Universe.Tree
A factory method for Apply nodes.
Run Code Online (Sandbox Code Playgroud)
但是我如何弄清楚Apply节点是什么?我在哪里可以找到AST的节点类型列表,以及它们如何组合在一起?
我正在寻找替代-print或javap作为一种方法来确定编译器在Scala中正在做什么.随着新的反射/宏库,reify似乎应该是一个很好的候选人,如在返璞词的宏观的desugar.它甚至展示了人们如何做到这一点,前M4.
所以问题是,在Scala 2.10.0-M4之后,我可以在Scala的REPL上输入最短/最简单的东西来获取表达式的AST?
假设我有一些嵌套特征:
trait Foo { trait Bar }
Run Code Online (Sandbox Code Playgroud)
还有几个例子:
val myFoo = new Foo {}
val myBar = new myFoo.Bar {}
Run Code Online (Sandbox Code Playgroud)
我可以写下面的内容,看起来(至少一目了然)就像他们应该或多或少地做同样的事情:
def whatever1(foo: Foo)(bar: foo.Bar) = bar
def whatever2(foo: Foo): foo.Bar => foo.Bar = { bar => bar }
def whatever3(foo: Foo) = new { def apply(bar: foo.Bar) = bar }
case class whatever4(foo: Foo) { def apply(bar: foo.Bar) = bar }
case class whatever5[F <: Foo](foo: F) { def apply(bar: foo.Bar) = bar }
Run Code Online (Sandbox Code Playgroud)
请注意,最后一个受到此处给出的解决方案的启发.
前三项工作: …
types scala nested-class path-dependent-type dependent-method-type