0

有谁知道为什么以下代码无法将 ∙ 识别为有效的中缀运算符?

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
4

3 回答 3

6
于 2011-11-14T14:26:30.407 回答
4

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
于 2011-11-14T14:36:41.150 回答
3
于 2011-11-14T14:45:51.883 回答