title: Why does Haskell's "do nothing" function, id, consume tons of memory?
body: <p>Haskell has an identity function which returns the input unchanged. The definition is simple:</p>
  
  <pre><code>id :: a -&gt; a
  id x = x
  </code></pre>
  
  <p>So for fun, this should output <code>8</code>:</p>
  
  <pre><code>f = id id id id id id id id id id id id id id id id id id id id id id id id id id id
  main = print $ f 8
  </code></pre>
  
  <p>After a few seconds (and about 2 gb of memory according to Task Manager), compilation fails with <code>ghc: out of memory</code>. Similarly, the interpreter says <code>ghci: out of memory</code>.</p>
  
  <p>Since <code>id</code> is a pretty simple function, I wouldn't expect it to be a memory burden at run time or compile time. What is all the memory being used for?</p>