GHC panic with ViewPatterns and GADTs in a proc pattern
The following code causes a ghc panic with versions 7.8.4 and 7.9.
module A where
{-# LANGUAGE GADTs, ViewPatterns, PatternSynonyms, DataKinds, Arrows, TypeOperators, TypeFamilies, UndecidableInstances #-}
import Control.Arrow
data Nat = Z | S Nat
data Vec n a where
VNil :: Vec Z a
VCons :: a -> Vec n a -> Vec (S n) a
viewVNil :: Vec Z a -> ()
viewVNil VNil = ()
viewVCons :: Vec (S n) a -> (a, Vec n a)
viewVCons (VCons a as) = (a, as)
pattern (:>) :: a -> Vec n a -> Vec (S n) a
pattern a :> as <- (viewVCons -> (a, as))
pattern VNil' <- (viewVNil -> ())
type family n + m where
n + Z = n
n + S m = S (n + m)
type family P2 n where
P2 Z = S Z
P2 (S n) = P2 n + P2 n
class A n where
a :: Arrow b => b (Vec (P2 n) a) a
instance A Z where
a = proc (a :> VNil) -> returnA -< a
If the pattern (a :> VNil) is changed to (a :> _) or (a :> VNil'), the code compiles.
GADTs pattern are not allowed to appear in proc patterns, but view patterns seems to be able to bypass this restriction, #9953 (closed), and the check on subpatterns.
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.4 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |