title: Tail recursive function to find depth of a tree in Ocaml
body: <p>I have a type <code>tree</code> defined as follows</p>
  
  <pre><code>type 'a tree = Leaf of 'a | Node of 'a * 'a tree * 'a tree ;;
  </code></pre>
  
  <p>I have a function to find the depth of the tree as follows</p>
  
  <pre><code>let rec depth = function 
      | Leaf x -&gt; 0
      | Node(_,left,right) -&gt; 1 + (max (depth left) (depth right))
  ;;
  </code></pre>
  
  <p>This function is not tail recursive. Is there a way for me to write this function in tail recursive way? </p>