title: Why do 3 and x (which was assigned 3) have different inferred types in Haskell?
body: <p>Type inference in Haskell has a bit of a learning curve (to say the least!). A good way to start learning it is with simple examples. So, the following is a bit of a "hello world" for type inference.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>Prelude&gt; :t 3
  3 :: (Num t) =&gt; t
  Prelude&gt; let x = 3
  Prelude&gt; :t x
  x :: Integer
  </code></pre>
  
  <p>The question is thus: <strong>Why do 3 and x have different types?</strong></p>
  
  <p><strong>Link Summary:</strong></p>
  
  <p>Read the answers below for the full story; here's just a link summary:</p>
  
  <ol>
  <li>GHC type defaulting: <a href="http://www.haskell.org/onlinereport/decls.html" rel="noreferrer">Haskell Report section
  4.3.4</a></li>
  <li>GHCi's extended type defaulting: <a href="http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/interactive-evaluation.html#extended-default-rules" rel="noreferrer">Using GHCi section
  2.4.5</a></li>
  <li>Monomorphic Restriction: <a href="http://www.haskell.org/haskellwiki/Monomorphism_restriction" rel="noreferrer">Haskell
  wiki</a></li>
  </ol>