fun sq(n :: Number): n * n end
modulo-power :: Number, Number, Number -> Number
fun modulo-power(base, exp, n):
if exp == 0:
1
else:
if num-round-even(exp):
num-modulo(sq(modulo-power(base, (exp / 2), n)), n)
else:
num-modulo(base * modulo-power(base, (exp - 1), n), n)
end
end
end
The problem is num-round-even returns a number, and hence can't be used in a test position.
The type error does indeed say
However, note what it highlights:
The Boolean is actually the conditional position. Also, the then-clause has nothing to do with this.
Here's a full program:
The problem is
num-round-even
returns a number, and hence can't be used in a test position.The type error does indeed say
However, note what it highlights:
The Boolean is actually the conditional position. Also, the then-clause has nothing to do with this.