blob: a09f26b058fbee0446e210b30051ca290e1115ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
object Sum {
def sum (f: Int => Int, a: Int, b: Int) = {
def loop(a: Int, acc: Int): Int =
if (a > b) acc
else loop(a + 1, f(a) + acc)
loop(a, 0)
}
def run =
println(sum(x => x * x, 3, 5))
}
|