我无法围绕以下功能组合:
function plus_one(x) {
return x + 1;
}
function trans(f) {
return function(x) {
return 2 * f(2 * x);
};
}
function twice(f) {
return function(x) {
return f(f(x));
}
}
当我尝试评估((twice)(trans))(plus_one)(1)
该结果时,假设plus_one
为f, f(2f(2x))=2f(2*2f(2x))=2f(4f(2x)) = 2*(4*(2 + 1)) = 24.
但将其键入解释器后将显示为20。
任何帮助是极大的赞赏。
非常感谢高级。
((twice)(trans))(plus_one)
是trans(trans(plus_one))
和
trans(trans(plus_one)) (1)
—> trans(λx.2 * plus_one(2*x)) (1)
—> λy.2 * ((λx.2 * plus_one(2*x))(2*y) (1)
—> 2 * (λx.2 * plus_one(2*x)) (2*1)
-> 2 * 2 * plus_one(2*2)
-> 2 * 2 * 5
-> 20
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句