GHCi :print produces variables that cause a panic
Using ghci installed by Stack, I noted some strange behaviour from the :sprint and :print commands:
λ> xs = [1,2,3]
λ> :sprint xs
xs = _
λ> head xs
1
λ> :sprint xs
xs = _
λ> :print xs
xs = (_t1::Num a => [a])
λ> _t1
<interactive>:6:1: error:
• No instance for (Num a) arising from a use of ‘_t1’
• In the expression: _t1
In an equation for ‘it’: it = _t1
λ> :t _t1
<interactive>:1:1: error:
No instance for (Num a) arising from a use of ‘_t1’
λ> :info _t1
_t1 :: Num a => [a] -- Defined in ‘interactive:Ghci3’
λ> _t1 :: [Int]
<interactive>:9:1: error:ghc: panic! (the 'impossible' happened)
(GHC version 8.2.2 for x86_64-unknown-linux):
No skolem info:
a_a1rR
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
pprPanic, called at compiler/typecheck/TcErrors.hs:2653:5 in ghc:TcErrors
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
I don't really understand the error, or why even the :type command fails, but it appears to be related to the way numeric types are polymorphic until a specific type is forced. Note that the both the :sprint and :print commands don't seem to recognise that we've evaluated any of xs, just printing an underscore no matter what.
The panic doesn't happen if I force a type when defining xs:
λ> xs = [1,2,3] :: [Int]
λ> :sp xs
xs = _
λ> head xs
1
λ> :sp xs
xs = 1 : _
λ> :print xs
xs = 1 : (_t2::[Int])
λ> _t2
[2,3]
λ> :t _t2
_t2 :: [Int]
λ> :in _t2
_t2 :: [Int] -- Defined in ‘interactive:Ghci6’
λ> _t2 :: [Integer]
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | GHCi |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |