title: STUArray s i e - space leak only when i == Int?
body: <p>I am confused by the behaviour of the following snipped:</p>
  
  <pre><code>import Data.Int
  import Data.Array.ST
  import Control.Monad.ST
  
  {-# INLINE fib #-}
  fib _ 0 = return 0
  fib _ 1 = return 1
  fib c n = do
    f1 &lt;- memo c (fib c) (n-1)
    f2 &lt;- memo c (fib c) (n-2)
    return (f1+f2)
  
  newtype C a = C a
  
  {-# INLINE memo #-}
  memo (C a) f k = do
    e &lt;- readArray a k
    if e == (-1)
       then do
         v &lt;- f k
         writeArray a k v
         return v
       else return e
  
  evalFib :: Int -&gt; Int
  evalFib n = runST $ do
    a &lt;- newArray (0,n) (-1) :: ST s (STUArray s Int Int)
    fib (C a) n
  
  main = print $ evalFib 120000
  </code></pre>
  
  <p>When compiled with <code>-O2</code> it stack-overflows (showing 20M of memory in use). The confusing part is that it actually works as expected (no stack overflow and 9M memory in use) if <em>any</em> of the following changes is made:</p>
  
  <ul>
  <li><code>Int64</code> is used instead of <code>Int</code>: (giving <code>evalFib :: Int64 -&gt; Int</code> and <code>STUArray s Int64 Int</code>). In fact any <code>Int*</code> (<code>Int32</code>, <code>Int16</code>, etc) will do the trick as well as <code>Word</code> or <code>Word*</code>;</li>
  <li><code>newtype C a</code> is removed from the picture;</li>
  <li><code>data C a = C !a</code> is used instead of <code>newtype</code></li>
  </ul>
  
  <p>I am trying to get my head around this behaviour: is it a bug in GHC/array module (it shows identical behaviour in <code>7.4.2</code> and <code>7.6.2</code>) or is it supposed to work that way?</p>
  
  <p>PS The funny thing is that when I try to compile it with <code>ghc array.hs -O2 -fext-core</code> to see the differences in core produced both GHC versions fail with "ghc: panic! (the 'impossible' happened)". No luck here either..</p>