Write a doItX :: (a -> a -> a) -> a -> Int -> a function that applies the first parameter f x times on the second parameter.
doItX (*) 2 1 == 2
doItX (++) "a" 6 == "aaaaaa"
doItX (*) 2 3 == 8
I have the following code:
doItX f a x
| x==1 = a
| x>1 = doItX f (f a a) (x-1)
That works fine if x is 2 or less, but for the third example, it returns 16 instead of 8.