因此,根据我所读到的内容,我得到了这种形式的currying:
def arithmetic_iter(op: (Int, Int) => Int, f: Int => Int, base: Int)(a: Int, b: Int): Int = {
def iter(a: Int, base: Int): Int =
if (a > b) base
else iter(a + 1, op(base, f(a)))
iter(a, base)
}
但是,我想做这样的事情:
def route(m:Message) = {
(e: Endpoint) => e.send(m)
}
有了上面的功能。所以我想出了这个数字:
def arithmetic_iter_lambda(op: (Int, Int) => Int, f: Int => Int, base: Int)(a: Int, b: Int): Int = {
(a: Int, b: Int) =>
Int = {
def iter(a: Int, base: Int): Int =
if (a > b) base
else iter(a + 1, op(base, f(a)))
iter(a, base)
}
}
不幸的是,我收到一条错误消息:重新分配给 val。
所以我坚持如何修复算术_iter_lambda。