def sum(f: Int => Int): (Int, Int) => Int = {Now, we can turn that into
def sumF(a: Int, b: Int): Int =
if (a > b) 0
else f(a) + sumF(a+1, b)
sumF
}
def sum(f: Int => Int)(a: Int, b: Int): Int =This way, we can still use sum without the second parameter list such as sum(cube).
if (a>b) 0 else f(a) + sum(f)(a+1, b)
No comments:
Post a Comment