title: Efficiency of Haskell Tail-recursive functions
body: <p>I have the following basic Haskell code:</p>
  
  <pre><code>prodsum x = prod x + sum x 
  
  prod 0 = 1
  prod n = n * prod (n-1)
  
  sum 0 = 0
  sum n = n + sum (n-1)
  </code></pre>
  
  <p>Can anyone explain me why the code below is more efficient:</p>
  
  <pre><code>prod' n = prodTR n 1
     where prodTR 0 r = r
           prodTR n r = prodTR (n-1) $! (r*n)
  
  sum' n = sumTR n 0
     where sumTR 0 r = r
           sumTR n r = sumTR (n-1) $! (r+n)
  
  prodsum' n = prod' n + sum' n
  </code></pre>