Skip to content

GHCi: internal error: stg_ap_p_ret

import Unsafe.Coerce
coerce = Unsafe.Coerce.unsafeCoerce

data Nat = Zero | Suc Nat

fromNat :: Nat -> Integer
fromNat Zero    = 0
fromNat (Suc l) = 1 + fromNat l

instance Show Nat where
  show l = show (fromNat l)

data Exp = Const Nat | Pred | App Exp Exp

eval :: Exp -> a
eval (Const n) = coerce n
eval e         = coerce $ evalP e
  where
    evalP Pred Zero    = Zero
    evalP Pred (Suc n) = n
    evalP e    n       = evalA e n

    evalA (App f e)    = eval f (eval e)
    evalA _            = error "eval"

-- With type signature, result is 0 (wrong, should be 1)
-- Without type signature: internal error: stg_ap_p_ret
-- test :: Nat
test = eval $ App Pred $ Const $ Suc $ Suc Zero

-- main prints 0 should maybe print 1
main :: IO ()
main = print (coerce test :: Nat)

when evaluatiing test at the ghci prompt after loading, I get

<interactive>: internal error: stg_ap_p_ret
    (GHC version 7.8.3 for x86_64_unknown_linux)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Process haskell aborted (core dumped)
Trac metadata
Trac field Value
Version 7.8.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC hvr
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information