0
這裏是2層的功能:Scala的遞歸,溢出
def Foo1(s: ((BigInt, Long) => Long)
=> ((BigInt, Long) => Long)): (BigInt, Long) => Long = s(Foo1(s))
def Foo2(s: (=> (BigInt, Long) => Long)
=> ((BigInt, Long) => Long)): (BigInt, Long) => Long = s(Foo2(s))
當它們被稱爲使用以下參數:
Foo1(rec => (x, s) =>
if (x == 1) s
else rec(if (x % 2 == 0) x/2 else 3 * x + 1, s + 1))(56, 0)
Foo2(rec => (x, s) =>
if (x == 1) s
else rec(if (x % 2 == 0) x/2 else 3 * x + 1, s + 1))(56, 0)
第一導致堆棧溢出,並且第二正常執行。
此外,這個表達式是什麼意思:(=> (BigInt, Long) => Long)
?