ОФП 2 лаба (12)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Number (n: Int) {
val value = n;
def unary_- () = new Number(-value)
def + (q: Number) = new Number (value+q.value)
def + (i: Int) = new Number (value+i)
def - (q: Number) = this + (-q)
def - (i: Int) = this + (- new Number(i))
def * (q: Number) = new Number(value*q.value)
def * (k: Int) = new Number (value*k)
}
class Converter (x: Int) {
def *(n: Number) = n * x
def -(n: Number) = (-n) + x
def +(n: Number) = (n) +x
}
implicit def intToFactor(i: Int) = new Converter(i)
val a = new Number(1)
val b = new Number(9)
val c = new Number(-1)
val d = 2-(a+b)*(-(5*c+3))
println(d.value)