title: foldl versus foldr behavior with infinite lists
body: <p>The code for the myAny function in <a href="https://stackoverflow.com/questions/833186/why-does-this-haskell-code-work-successfully-with-infinite-lists/833218">this question</a> uses foldr.  It stops processing an infinite list when the predicate is satisfied.</p>
  
  <p>I rewrote it using foldl:</p>
  
  <pre><code>myAny :: (a -> Bool) -> [a] -> Bool
  myAny p list = foldl step False list
     where
        step acc item = p item || acc</code></pre>
  
  <p>(Note that the arguments to the step function are correctly reversed.)</p>
  
  <p>However, it no longer stops processing infinite lists.</p>
  
  <p>I attempted to trace the function's execution as in <a href="https://stackoverflow.com/questions/833186/why-does-this-haskell-code-work-successfully-with-infinite-lists/833218#833218">Apocalisp's answer</a>:</p>
  
  <pre><code>myAny even [1..]
  foldl step False [1..]
  step (foldl step False [2..]) 1
  even 1 || (foldl step False [2..])
  False  || (foldl step False [2..])
  foldl step False [2..]
  step (foldl step False [3..]) 2
  even 2 || (foldl step False [3..])
  True   || (foldl step False [3..])
  True</code></pre>
  
  <p>However, this is not the way the function behaves.  How is this wrong?</p>