Panic in the Template Haskell
Summary
Write a brief description of the issue.
Steps to reproduce
Write a module like this
{-# language TemplateHaskellQuotes #-}
module SequenceCode where
import Data.Sequence.Internal
import qualified Language.Haskell.TH.Syntax as TH
class Functor t => SequenceCode t where
traverseCode :: TH.Quote m => (a -> TH.Code m b) -> t a -> TH.Code m (t b)
traverseCode f = sequenceCode . fmap f
sequenceCode :: TH.Quote m => t (TH.Code m a) -> TH.Code m (t a)
sequenceCode = traverseCode id
instance SequenceCode Seq where
sequenceCode (Seq t) = [|| Seq $$(traverseCode sequenceCode t) ||]
instance SequenceCode Elem where
sequenceCode (Elem t) = [|| Elem $$t ||]
instance SequenceCode FingerTree where
sequenceCode (Deep s pr m sf) =
[|| Deep s $$(sequenceCode pr) $$(traverseCode sequenceCode m) $$(sequenceCode sf) ||]
sequenceCode (Single a) = [|| Single $$a ||]
sequenceCode EmptyT = [|| EmptyT ||]
instance SequenceCode Digit where
sequenceCode (One a) = [|| One $$a ||]
sequenceCode (Two a b) = [|| Two $$a $$b ||]
sequenceCode (Three a b c) = [|| Three $$a $$b $$c ||]
sequenceCode (Four a b c d) = [|| Four $$a $$b $$c $$d ||]
instance SequenceCode Node where
sequenceCode (Node2 s x y) = [|| Node2 s $$x $$y ||]
sequenceCode (Node3 s x y z) = [|| Node3 s $$x $$y $$z ||]
Then write another one importing it and doing thus:
{-# LANGUAGE TemplateHaskell, ScopedTypeVariables #-}
glumber :: forall a. Num a => a -> Seq a
glumber x = $$(sequenceCode (fromList [TH.liftTyped _ :: TH.Code TH.Q a, [||x||]]))
Result:
tests/seq-properties.hs:974:40: error:
• No instance for (TH.Lift a) arising from a use of ‘TH.liftTyped’
• In the expression: TH.liftTyped _ :: TH.Code TH.Q a
In the first argument of ‘fromList’, namely
‘[TH.liftTyped _ :: TH.Code TH.Q a, [|| x ||]]’
In the first argument of ‘sequenceCode’, namely
‘(fromList [TH.liftTyped _ :: TH.Code TH.Q a, [|| x ||]])’
|
974 | glumber x = $$(sequenceCode (fromList [TH.liftTyped _ :: TH.Code TH.Q a, [||x||]]))
| ^^^^^^^^^^^^
tests/seq-properties.hs:974:53: error:ghc: panic! (the 'impossible' happened)
(GHC version 9.2.1:
No skolem info:
[a_aaba[sk:1]]
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Tc/Errors.hs:2888:17 in ghc:GHC.Tc.Errors
Expected behavior
I expect my error messages not to be accompanied by panics.
Environment
- GHC version used: 9.2.1
Optional:
- Operating System:
- System Architecture: