title: Is this a correct way of writing the Haskell foldr function?
body: <p>I was doing the exercises from <a href="http://en.wikibooks.org/wiki/Haskell/YAHT/Type_basics#Recursive_Datatypes" rel="nofollow noreferrer">YAHT's Recursive Datatype</a> section, and found writing the <code>listFoldr</code> function a bit challenging (mainly because I didn't really understand the difference between <code>foldl</code> and <code>foldr</code> at first). When I finally realized exactly how the <code>foldr</code> function worked, I decided that a simple swap of function arguments would be all that'd be needed to change my <code>listFoldl</code> function to a <code>listFoldr</code> function:</p>
  
  <pre><code>listFoldl f i [] = i
  listFoldl f i (x:xs) = listFoldl f (f i x) xs
  
  listFoldr f i [] = i
  listFoldr f i (x:xs) = listFoldr f (f x i) xs
  </code></pre>
  
  <p>This appears to work (I did more tests than this):</p>
  
  <pre><code>Main&gt; foldr (-) 4 [1, 2, 3]
  -2
  Main&gt; listFoldr (-) 4 [1, 2, 3]
  -2
  </code></pre>
  
  <p>But the <a href="http://en.wikibooks.org/wiki/Haskell/YAHT/Type_basics/Solutions#Recursive_Datatypes" rel="nofollow noreferrer">solution</a> given for the exercise is much different than mine. Their <code>listFoldl</code> is exactly the same as mine, but look at their <code>listFoldr</code>:</p>
  
  <pre><code>listFoldr f i [] = i
  listFoldr f i (x:xs) = f x (listFoldr f i xs)
  </code></pre>
  
  <p>Which solution is better, mine or theirs? Is one of them incorrect? (In my tests, they both end up with the exact same result...)</p>