panic validHoleFits no evdest
Summary
I was playing around with two-level free monads and encountered a panic for this program:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuantifiedConstraints #-}
module Panic where
import Control.Monad
import Data.Type.Equality
import Data.Kind
type Name :: Type -> Type
newtype Name a = Name Int
newtype TL f g a = TL { unTL :: Freer f (FreerS g a) }
instance Functor (TL f g) where
instance Applicative (TL f g) where
instance Monad (TL f g) where
data Freer f a = Pure a | forall x. Freer (f x) (x -> Freer f a)
instance Functor (Freer f) where
instance Applicative (Freer f) where
instance Monad (Freer f) where
data FreerS f a = PureS a | forall x. FreerS (f (Name x)) (Name x) (FreerS f a)
instance Functor (FreerS f) where
instance Applicative (FreerS f) where
instance Monad (FreerS f) where
class Alpha a where
rename :: Name b -> Name b -> a -> a
data (f + g) x = L (f x) | R (g x)
data Count a where
Incr :: Count ()
handleM
:: forall a b h g f t. (Alpha a, forall x. Alpha (g x), forall x. Alpha (f x))
=> (forall x. g x -> h x)
-> (a -> TL t h b)
-> (forall x. f (Name x) -> (Name x -> TL t h b) -> TL t h b)
-> TL t (f + g) a
-> TL t h b
handleM sub gen alg = flush >=> go where
go :: FreerS (f + g) a -> TL t h b
go (PureS x) = gen x
go (FreerS op n k) =
case op of
L op' -> alg op' (\n' -> go (rename n n' k))
R op' -> hoist (FreerS (sub op') n) (go k)
flush :: TL f g a -> TL f g' (FreerS g a)
flush (TL m) = TL (fmap pure m)
count :: TL (Count + f) g a -> TL f g (Int, a)
count = handleM id (raise . fmap (0,)) $ \op k ->
case op of
Incr -> k _
I know there's a bug in this program in that I wanted to use another handleC
function instead of handleM
in count
, but I didn't expect the panic:
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.4.4:
validHoleFits no evdest
[G] Name x_a1bc[sk:2] ~# ()
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:182:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Tc/Errors.hs:1459:22 in ghc:GHC.Tc.Errors
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Environment
- GHC version used: 9.4.4