如何iterate
修改功能以使结果为
f x, (f^2)x, (f^4)x, (f^8)x, ...
如果有人可以向我提供任何建议,我将非常高兴。
Given, that f^x
means f
x-times applied to x
I would say
iterate :: (a -> a) -> a -> [a]
iterate f x = f x : iterate (f . f) x
would suffice.
选择:
Prelude> map snd $ iterate (\(f,x) -> (f.f, f x)) ((+1),1)
[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,...