Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How can be iterate function modified that the result will be
iterate
f x, (f^2)x, (f^4)x, (f^8)x, ...
I'd be very happy if anybody could provide me with any suggestion.
Given, that f^x means f x-times applied to x I would say
f^x
f
x
iterate :: (a -> a) -> a -> [a] iterate f x = f x : iterate (f . f) x
would suffice.
Add a comment
Alternative:
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,...
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.