有谁知道为什么以下代码无法将 ∙ 识别为有效的中缀运算符?
object Main extends App {
val c = (I() ∙ I())
}
sealed abstract class Term
case class I() extends Term
case class ∙(x: Term, y: Term) extends Term
有谁知道为什么以下代码无法将 ∙ 识别为有效的中缀运算符?
object Main extends App {
val c = (I() ∙ I())
}
sealed abstract class Term
case class I() extends Term
case class ∙(x: Term, y: Term) extends Term
To put it simply, because it is not. It is an object
and a class
, but not a method, and only methods can be operators (infix or not).
As an object, you can use it on pattern matches:
case a ∙ b =>
As a class, if it had two type parameters, it would use it on type declarations:
type X = Int ∙ String