title: Creating infix operators in Scala
body: <p>I am trying to translate some of my Haskell code into Scala and I am having difficulty with creating infix operators.</p>
  
  <p>In Haskell say I have this infix operator defined as:</p>
  
  <pre><code>infix 1 &lt;=&gt;                          // this specifies the operator precedence
  (&lt;=&gt;) :: Bool -&gt; Bool -&gt; Bool        // this is the type signature of this operator (it says, it takes two Boolean values and returns a Boolean value)
  x &lt;=&gt; y = x == y                     // this is the definition of the operator, it is mimicking the behaviour of the logical implication 'if-and-only-if'
  </code></pre>
  
  <p>So now if I have two booleans, p and q where p == True and q == False, p &lt;=> q will return False.</p>
  
  <p>My question is how do I go about translating this into Scala. I had a look at the Rational class defined in Odersky's Programming in Scala book and
  tried to follow the example. This is as far as I got:</p>
  
  <pre><code>class Iff (b : Boolean){
    def &lt;=&gt; (that : Boolean) : Boolean = {
      this.b == that
    }
  }
  
  val a = new Iff(true)
  println(a.&lt;=&gt;(false))  // returns false as expected
  </code></pre>
  
  <p>I've probably not done this in idiomatic Scala so I am looking for help in that department.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Have I implemented this idiomatically in Scala? If not, what is that best way to this in Scala?</li>
  <li>Did I have to create that class in order to define this operator? Meaning, can I define a standalone method in Scala like I have in the Haskell code above?</li>
  <li>How to specify the fixity level of the operator in Scala? That is, it's precedence level.</li>
  </ol>