Skip to content

GHC Panic with PolyKinds and TypeFamilies

The following crashes:

  {-# LANGUAGE TypeOperators, PolyKinds, TypeFamilies, ExplicitForAll, GADTs #-}

  module GHCBug where

  data Nat = Zero | Succ Nat

  data NatV (a :: Nat) where
    ZeroV :: NatV Zero
    SuccV :: NatV n -> NatV (Succ n)

  data Phantom t = Whoo

  data ListV (a :: [*]) where
    NilV :: ListV '[]
    (:::) :: Phantom a -> ListV as -> ListV (a ': as)

  type family (:+:) (a :: Nat) (b :: Nat) :: Nat
  type instance Zero :+: b = b
  type instance (Succ a) :+: b = Succ (a :+: b)

  type family TReplicate (n :: Nat) (t :: *) :: [*]
  type instance TReplicate Zero t = '[]
  type instance TReplicate (Succ n) t = t ': TReplicate n t

  replicateTList :: forall (n :: Nat). forall t.
		    NatV n -> Phantom t -> ListV (TReplicate n t)
  replicateTList ZeroV _ = NilV
  replicateTList (SuccV n) t = t ::: replicateTList n t

Potentially related to 5717 and 5768, although those two seem to be related to ScopedTypeVariables? They also seem to have a different panic message, although maybe this is because I'm using a debug-built GHC?

I'm not actually using 7.4.1-rc1, but 7.4 HEAD at the time of this writing.

Trac metadata
Trac field Value
Version 7.4.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information