如何让 scala 编译器递归查找隐式视图?
type Expression = () => String
implicit def constant(s: String): Expression = () => s
implicit def evaluation[A <% Expression](exprs: Seq[A]): Expression = () => exprs match {
case "concat" :: args => args.map(_.apply()).mkString
}
Seq("concat", "foo", "bar")() // This works
Seq("concat", "foo", Seq("concat", "bar", "baz"))() // No implicit view available from java.lang.Object => () => String.
我知道最后一个序列具有Object
没有隐式视图的通用类型,但是如何在不诉诸动态模式匹配的情况下定义类型安全的AnyRef
?
在 Scala 2.9.2 中尝试过