title: Why does foldr use a helper function?
body: <p>In explaining <code>foldr</code> to Haskell newbies, the canonical definition is</p>
  
  <pre><code>foldr            :: (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
  foldr _ z []     =  z
  foldr f z (x:xs) =  f x (foldr f z xs)
  </code></pre>
  
  <p>But in GHC.Base, <code>foldr</code> is defined as</p>
  
  <pre><code>foldr k z = go
            where
              go []     = z
              go (y:ys) = y `k` go ys
  </code></pre>
  
  <p>It seems this definition is an optimization for speed, but I don't see why using the helper function <code>go</code> would make it faster. The source comments (<a href="http://hackage.haskell.org/package/base-4.7.0.1/docs/src/GHC-Base.html#foldr">see here</a>) mention inlining, but I also don't see how this definition would improve inlining.</p>