[GHC] #10166: GHCi: internal error: stg_ap_p_ret

#10166: GHCi: internal error: stg_ap_p_ret -------------------------------------+------------------------------------- Reporter: | Owner: andreas.abel | Status: new Type: bug | Milestone: Priority: normal | Version: 7.8.4 Component: GHCi | Operating System: Unknown/Multiple Keywords: | Type of failure: None/Unknown Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- {{{#!hs 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) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10166 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10166: GHCi: internal error: stg_ap_p_ret -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by monoidal): * status: new => closed * resolution: => invalid Comment: Letting X be a shortcut for `Const (Suc (Suc Zero))`, your program makes an evaluation step {{{ eval (App Pred X) => coerce $ evalP (App Pred X)` }}} and attempts to print this as a `Nat`, but `evalP (App Pred X)` is a function (evalP takes two arguments), that's an invalid coercion. If you change your `eval` to {{{#!hs eval :: Exp -> a eval (Const n) = coerce n eval Pred = coerce pr eval (App f e) = coerce (eval f (eval e)) pr Zero = Zero pr (Succ n) = n }}} then it works on my machine, but you should use `Any` for such tricks (https://hackage.haskell.org/package/ghc-prim-0.3.1.0/docs/GHC- Prim.html#v:unsafeCoerce35-). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10166#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10166: GHCi: internal error: stg_ap_p_ret -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): Yes, there's a reason that `unsafeCoerce` is called "`unsafeCoerce`" :-). Renaming it to `coerce` is arguably misleading, especially since `Data.Coerce` exports a guaranteed-sound function `coerce`! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10166#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10166: GHCi: internal error: stg_ap_p_ret -------------------------------------+------------------------------------- Reporter: andreas.abel | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.8.4 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): (And this is a task that [http://en.wikibooks.org/wiki/Haskell/GADT GADTs] are well-suited for, in place of `unsafeCoerce`.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10166#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC