I am trying to figure out recursion for OCaml in the context of an object's method. I have tried the following code but can't seem to get it to compile.
class foo =
object (self)
method loopTest =
let rec doIt x =
Printf.printf "%d\n" x;
if x>1 then doIt (x+1)
end;;
How do I create a recursive function of this sort within a method?
Revised code:
class foo =
object (self)
method loopTest =
let rec doIt x =
Printf.printf "%d\n" x;
if x<10 then doIt (x+1) in doIt 0
end;;