Opened 5 years ago

Last modified 4 years ago

#9985 new bug

GHC panic with ViewPatterns and GADTs in a proc pattern

Reported by: Rafbill Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.8.4
Keywords: Arrows, GADTs Cc: ross
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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, and the check on subpatterns.

Change History (3)

comment:1 Changed 5 years ago by simonpj

Cc: ross added

Ross, any views? Other open tickets on arrows are #7828, #5267, #5777, #5333, #344.


comment:2 Changed 4 years ago by thomie

Component: CompilerCompiler (Type checker)
Keywords: Arrows added

comment:3 Changed 4 years ago by thomie

Keywords: GADTs added
Note: See TracTickets for help on using tickets.