GHC: Ticket #6012: No warning for Incorrect display of 15! (factorial 15) when type is Int -> Int
http://ghc.haskell.org/trac/ghc/ticket/6012
<p>
GHCi version: 7.0.4
</p>
<p>
Offending function:
</p>
<p>
factorial :: Int -> Int
factorial 0 = 1
factorial n = n * factorial (n-1)
</p>
<p>
Correct answer is displayed (as expected) when type is
</p>
<p>
factorial :: Integer -> Integer
</p>
<p>
THE <span class="wikiextras phrase fixme">BUG</span> IS THE DISPLAY OF A CORRECT-LOOKING INCORRECT ANSWER THAT RESULTED FROM (UNREPORTED) OVERFLOW OF Int (but not of Integer)
</p>
<p>
<del> Thank you
</del></p>
en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/6012
Trac 1.0.7dtereiTue, 17 Apr 2012 06:31:44 GMTstatus changed; resolution set
http://ghc.haskell.org/trac/ghc/ticket/6012#comment:1
http://ghc.haskell.org/trac/ghc/ticket/6012#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>invalid</em>
</li>
</ul>
<p>
1) Calm down.
</p>
<p>
2) Please check the Haskell language specification. Int is a bounded integer value guaranteed to be at least 30 bits long. The results of overflow are unspecified by the Haskell language specification and up to implementations to handle how they want. So GHC chooses to silently overflow.
</p>
<pre class="wiki">The finite-precision integer type Int covers at least the range
[ − 229, 229 − 1]. As Int is an instance of the Bounded class,
maxBound and minBound can be used to determine the exact
Int range defined by an implementation. Float is
implementation-defined; it is desirable that this type be at least
equal in range and precision to the IEEE single-precision type.
Similarly, Double should cover IEEE double-precision. The
results of exceptional conditions (such as overflow or underflow)
on the fixed-precision numeric types are undefined; an
implementation may choose error (⊥, semantically), a truncated
value, or a special value such as infinity, indefinite, etc.
</pre><p>
<a class="ext-link" href="http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4"><span class="icon"></span>http://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4</a>
</p>
<p>
3) Integer works as you expect as Integer is an unbounded integer value. So it will always be be big enough to represent the value you need. However this makes it a lot slower than an Int.
</p>
Ticket