I am trying to write this function that applies function f to x twice
Prelude> applyTwice :: (a -> a) -> a -> a Prelude> let applyTwice fx = f (fx)
Now when I try to evaluate the expression below
Prelude> applyTwice (`subtract` 3) 10 Output: 10 Prelude> applyTwice (3 `subtract`) 10 Output: 4
According to my understanding, subtract is an infix function, so this parameter should fill in an empty position (left or right operand), and therefore, the first applyTwice (`subtract` 3) 10 expression should behave like
10 `subtract` 3 `subtract` 3
So, the result in this case should be 4 , but output 10
While in another case, i.e. applyTwice (3 `subtract`) 10 , output 4 , where I expect it to be 10
Am I mistaken somewhere?
source share