title: Recursive functions within OCaml objects
body: <p>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.</p>
  
  <pre><code>class foo =
  object (self)
   method loopTest =
    let rec doIt x =
     Printf.printf "%d\n" x;
     if x&gt;1 then doIt (x+1)
  end;;
  </code></pre>
  
  <p>How do I create a recursive function of this sort within a method?</p>
  
  <p>Revised code:</p>
  
  <pre><code>class foo =
  object (self)
   method loopTest =
    let rec doIt x =
     Printf.printf "%d\n" x;
     if x&lt;10 then doIt (x+1) in doIt 0
  end;;
  </code></pre>