You have to write a function that is simplified version of foldl
or foldr
, depending on f
associativity. But, since you missed parenthesis in your examples, I suppose f
is right associative.
The code will be for your foldr
case:
fun compound f x 0 = x
| compound f x n = f(x, compound f x (n-1));