title: Mistake in this fold implementation
body: <p>In <a href="http://www.seas.upenn.edu/~cis194/lectures/02-lists.html" rel="nofollow">this lecture</a> about Haskell programming, there is a fold implementation, defined like so :</p>
  
  <pre><code>fold :: (a -&gt; b -&gt; b) -&gt; b  -&gt; [a] -&gt; b
  fold f z []     = z
  fold f z (x:xs) = f x (fold z f xs)
  </code></pre>
  
  <p>The idea is to use it to define sum, product, etc...</p>
  
  <pre><code>sum''     = fold (+) 0
  product'' = fold (*) 1
  length''  = fold addOne 0
   where addOne _ s = 1 + s
  </code></pre>
  
  <p>There seems to be an inversion between <code>z</code> and <code>f</code> inside the recursion pattern: otherwise, how could <code>z f xs</code> match <code>(a -&gt; b -&gt; b) -&gt; b  -&gt; [a]</code>?</p>
  
  <p>In my opinion, the recursion pattern should be </p>
  
  <pre><code>fold f z (x:xs) = f x (fold f z xs)
  </code></pre>
  
  <p>However, shortly after in the lecture, you can find the following statement:</p>
  
  <pre><code>fold f z [a,b,c] = a `f` (b `f` (c `f` z))
  </code></pre>
  
  <p>This reinforces the so-called mistake, so I guess there must be a mistake in my head instead!</p>
  
  <p>Shouldn't it be more like the following ?</p>
  
  <pre><code>fold f z [a,b,c] = `f` a (`f` b (`f` c z))
  </code></pre>
  
  <p>Am I missing a point, or is it a double mistake in the lecture?</p>