【发布时间】:2014-06-06 16:18:09
【问题描述】:
我在 scala 中遇到了一些类似形式的代码:
def test1(f : Int => Int)(x : Int) = x + f(x)
def test2(f : Int => Int)(x : Int) = f(x)
test2(test1(x => 2*x))(2)
我很困惑,所以函数 test1 将一个函数和一个 Int 作为参数,并返回一个函数,对吗?那么test1(x => 2*x)如何才能有效并返回一个函数给test2呢?显然它需要 2 作为整数参数,但为什么呢? test2(test1(x => 2*x))(2)这个语句是怎么展开的?
提前致谢。
【问题讨论】:
标签: scala functional-programming currying