Unary operator definitions for custom types in Scala
<p>Tried running this code:</p>
<p><code>def ! : Int =&gt; Boolean = (p : Int =&gt; Boolean) =&gt; !p</code></p>
<p>Has a compilation error:</p>
<pre><code>[error] value unary_! is not a member of Int =&gt; Boolean  
[error]   def ! : Int =&gt; Boolean = (p : Int =&gt; Boolean) =&gt; !p  
</code></pre>
<p>error is highlighted for &quot;!p&quot;</p>
<p>Shouldn't the compiler automatically figure out that the result of p is a <code>Boolean</code> ?</p>
<p>Thanks in advance</p>
<p>EDIT: Based on comments, tried the following also. Have accomplished my task using other methods, nonetheless, am trying to learn how to define an unary operator</p>
<p><code>def unary_! : Int =&gt; Boolean = (p : Int =&gt; Boolean) =&gt; !(p(_))</code></p>
<p>still getting a compiler error at <code>&quot;!(p(_))&quot;</code></p>