I'm trying to run the Scala code presented in this math.stackexchange post (please see the second answer), but seem to be running into issues in the line starting with implicit def...
. The compiler is telling me error: expected start of definition
.
Any thoughts? Thanks!
I should add that I'm using http://www.tutorialspoint.com/compile_scala_online.php to run my code.
Just tried your example on Scala REPL and it works for me as expected.
Move the implicit def
to an object:
object MyImplicits {
/** Pimp `Set[X]` with a few convenient operators */
implicit def logicalSetOps[X](set: Set[X]) = new {
def and(other: Set[X]) = set.intersect(other)
def or(other: Set[X]) = set.union(other)
def minus(other: Set[X]) = set.filterNot(other.contains)
}
}
and then do:
import MyImplicits._
That should work for you.
The code in that example is meant to be pasted either into a worksheet or into the REPL.
It should also work to paste it inside an
object MathApp extends App {
// paste here
}
Then you can run MathApp as scala or java application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With