title: Understanding Haskell's Laziness
body: <p>I was reading: <a href="https://stackoverflow.com/questions/16799755/haskell-interact-function">Haskell interact function</a></p>
  
  <p>So I tried</p>
  
  <pre><code>interact (unlines . map (show . length) . lines)
  </code></pre>
  
  <p>And it worked as I expected. I type something, press enter, then I get the length printed at the prompt.</p>
  
  <p>So then I wanted to try make it simply repeat what I typed, so I tried</p>
  
  <pre><code>interact (unlines . map id . lines)
  </code></pre>
  
  <p>But now it repeats every character I type in. Why is that? I thought the trick was in the <code>lines</code> followed by <code>unlines</code> - but it's clearly not. <code>lines "a"</code> produces <code>["a"]</code>, so how come in the first function when I start typing my input, it doesn't just immediately give "1" as the output? There's clearly something I misunderstand about "Finding the length of a string is not like this -- the whole string must be known before any output can be produced."</p>