title: Practical use of `foldl`
body: <p>Today when I was working on one little script I used <code>foldl</code> instead of <code>foldl'</code>. I got <code>stack overflow</code>, so I imported <code>Data.List (foldl')</code> and was happy with this. And this is my default workflow with <code>foldl</code>. Just use <code>foldl'</code> when lazy version falls to evaluate.</p>
  
  <p><code>Real World Haskell</code> says that we should use <code>foldl'</code> instead of <code>foldl</code> in most cases. <a href="http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27" rel="noreferrer">Foldr Foldl Foldl'</a> says that </p>
  
  <blockquote>
    <p>Usually the choice is between <code>foldr</code> and <code>foldl'</code>. </p>
    
    <p>...</p>
    
    <p>However, if the combining function is lazy in its first argument, <code>foldl</code> may happily return a result where <code>foldl'</code> hits an exception.</p>
  </blockquote>
  
  <p>And a given example:</p>
  
  <pre><code>(?) :: Int -&gt; Int -&gt; Int
  _ ? 0 = 0
  x ? y = x*y
  
  list :: [Int]
  list = [2, 3, undefined, 5, 0]
  
  okey = foldl (?) 1 list
  
  boom = foldl' (?) 1 list
  </code></pre>
  
  <p>Well, I am sorry, but it's rather academic, interesting but academic example. So I am asking, is there any example of practical use of <code>foldl</code>? I mean, when we can't replace <code>foldl</code> with <code>foldl'</code>. </p>
  
  <p>P. S. I know, it's hard to define term <code>practical</code>, but I hope you will understand what I mean.</p>
  
  <p>P. P. S. I understand, why lazy <code>foldl</code> is default in haskell. I don't ask anybody to move the mountain and make strict version as default. I am just really interested in examples of exclusive usage of <code>foldl</code> function :)</p>
  
  <p>P. P. P. S. Well, any interesting usage of <code>foldl</code> is welcome. </p>