title: Haskell: tail recursion version of depth of binary tree
body: <p>First of all I have two different implementation that I believe are correct, and have profiled them and thinking they are about of the same performance:</p>
  
  <pre><code>depth::Tree a -&gt; Int
  depth Empty        = 0
  depth (Branch b l r) = 1 + max (depth l) (depth r)
  
  
  depthTailRec::Tree a -&gt; Int
  depthTailRec = depthTR 0 where
             depthTR d Empty          = d 
             depthTR d (Branch b l r) = let dl = depthTR (d+1) l; dr = depthTR (d+1) r in max dl dr 
  </code></pre>
  
  <p>I was just wondering aren't people are talking about how tail recursion can be beneficial for performance? And a lot of questions are jumping into my head:</p>
  
  <ol>
  <li>How can you make the depth function faster?</li>
  <li>I read about something about how Haskell's laziness can reduce the need of tail recursion, is that true?</li>
  <li>Is it the truth that every recursion can be converted into tail recursion?</li>
  <li>Finally tail recursion can be faster and space efficient because it can be turned into loops and thus reduce the need to push and pop the stack, is my understanding right?</li>
  </ol>