I started playing with Scala few days ago.
What I wanted to do is write a very small class that would represent natural numbers and I'd like it to be implicitly convertible from/to Int
. Honestly I haven't done a lot so far. Here is the code:
object main {
class Natural(n: Int) {
def isDividerOf(m: Natural): Boolean = m % n == 0
}
implicit def Int(m: Natural): Int = m
implicit def Natural(n: Int): Natural = new Natural(n)
def main(args: Array[String]) ={
println("test")
println(60 isDividerOf 600)
}
}
The code is able to compile, but when I run it (no matter the numbers I use as arguments to isDividerOf
) the program execution is paused/hung forever, in other words after printing test
it doesn't output anything no does it exit properly.
What am I doing wrong?