【发布时间】:2013-11-13 22:13:45
【问题描述】:
所以根据我读到的内容,我得到了这种形式的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。
【问题讨论】: