title: Haskell basic factorial not exiting?
body: <p>I'm learning Haskell, and am having trouble with a basic factorial function from <a href="http://learnyouahaskell.com/syntax-in-functions" rel="noreferrer">this tutorial</a>.</p>
  
  <p>Basically, I've defined a factorial as such:</p>
  
  <pre><code>Prelude&gt; let factorial 0 = 1
  Prelude&gt; let factorial n = n * factorial (n - 1)
  </code></pre>
  
  <p>The type checks out:</p>
  
  <pre><code>Prelude&gt; :t factorial
  factorial :: Num a =&gt; a -&gt; a
  </code></pre>
  
  <p>which makes sense. However, the behavior of this function doesn't. It results in <code>(interactive): out of memory</code> no matter what the input is.</p>
  
  <pre><code>Prelude&gt; factorial 5
  (interactive): out of memory
  </code></pre>
  
  <p>I have to assume this is an infinite recursive call leading to an out of memory error, but I'm not sure what could possibly be causing it. The same thing happens with <code>factorial 0</code>, even though I've explicitly declared this to be 1:</p>
  
  <pre><code>Prelude&gt; factorial 0
  (interactive): out of memory
  </code></pre>
  
  <p>Now, here's the weird part: If I define the factorial function in a file, it works fine. I create a file <code>tesths.hs</code> s.t.:</p>
  
  <pre><code>factorial 0 = 1
  factorial n = n * factorial (n - 1)
  </code></pre>
  
  <p>Then, if I go back to GHCI and run <code>:l tesths.hs</code>, I can execute <code>factorial 5</code> without error.</p>
  
  <p>What's going on here? </p>