Search code examples
scalaoperatorsinfix-notation

Using unicode symbol as an infix operator in Scala


Does anyone know why the following code doesn't recognize ∙ as a valid infix operator?

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

Solution

  • Define as method on I.

    sealed abstract class Term 
    case class II(x: Term, y: Term) extends Term
    case class I() extends Term {
        def ∙(o: Term) = II(this, o)
    }
    

    Now I() ∙ I() will work, returning II.


    Not sure what you are trying to achieve, though.