I want to define function which simply does
test(n, func) = f ∘ f ∘ f ∘ f ... (n times), and when n is 0, it returns identity function.
That is, test(10, func:x->x+3) 0 becomes 30.
So I wrote down this code...
let rec rec_test (n, func) a =
if n == 0 then a
else rec_test (n-1, func) func(a)
But it gives me this error at line 3.
Error: This expression has type 'a -> 'b
but an expression was expected of type 'a
The type variable 'a occurs inside 'a -> 'b
Why can't I use func(a) in line 3, like a variable?
func ais two variables. Did you mean(func a)?==. It works here, but doesn't do what you think it does and when you start using it on more complex types it will create weird bugs you don't understand. You want to use=to test equality between values.