There are many questions based on applyTwice, but none that relate to my problem. I understand that the applyTwice function defined like this:
applyTwice :: (a -> a) -> a -> a
applyTwice f a = f (f a)
applies a function twice. So if I have an increment function:
increment x = x + 1
and do
applyTwice increment 0
I get 2. But I don't understand these results:
applyTwice applyTwice applyTwice increment 0 -- gives 16
applyTwice applyTwice applyTwice applyTwice increment 0 -- gives 65536
applyTwice applyTwice applyTwice applyTwice applyTwice increment 0 -- stack overflow
I also know that
twice = applyTwice applyTwice increment
applyTwice twice 0 -- gives 8
I simply cannot wrap my head around these results, would love it if someone could explain. I apologize if this is something basic, as I'm just learning Haskell.