Tried running this code:
def ! : Int => Boolean = (p : Int => Boolean) => !p
Has a compilation error:
[error] value unary_! is not a member of Int => Boolean [error] def ! : Int => Boolean = (p : Int => Boolean) => !p error is highlighted for "!p"
Shouldn't the compiler automatically figure out that the result of p is a Boolean ?
Thanks in advance
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
def unary_! : Int => Boolean = (p : Int => Boolean) => !(p(_))
still getting a compiler error at "!(p(_))"
unary_!as in the error. Yourptakes anInt, so!p(42).p. So the!isn't negating the return value ofp, butpitself, and!isn't an operator defined for functions.