I am wondering whether Eliminators can help prove that this is valid:
I have a normal HList:
data HList (ts :: [Type]) where
HNil :: HList '[]
(:&:) :: t -> HList ts -> HList (t ': ts)
infixr 5 :&:
instance (Show (HList '[])) where
show _ = "[]"
instance (Show a, Show (HList ts)) => (Show (HList (a : ts))) where
show (a :&: rest) = show a ++ ":&:" ++ show rest
and a homogenous case
newtype HoHeList (n :: Nat) a = HoHeList
{ unHoHeList :: HList (Replicate n a)
}
now, i want to create a show-instance:
instance Show a => Show (HoHeList (n :: Nat) a) where
show = (show . unHoHeList)
and prove it via (i am using your cong):
type TypeClassInduction a (n :: Nat) (f :: [Type] -> Type) (t :: Type -> Constraint)
= t (f (Replicate n a))
$(genDefunSymbols [''TypeClassInduction])
typeClassInduction :: forall (n :: Nat) (a :: Type) (f :: [Type] -> Type) (t :: Type -> Constraint).
(SingI n, t (f '[a]), forall xs x. (t (f xs), t x) => t (f (x ': xs)))
=> TypeClassInduction a n f t
typeClassInduction = elimNat @(TypeClassInduction a n f t) @n (sing @Nat @n) base step
where
base :: TypeClassInduction a 0 f t
base = Refl
step :: forall (k :: Nat).
Sing k
-> TypeClassInduction a k f t
-> TypeClassInduction a (k :+ 1) f t
step _ = case replicateSucc @k @a of
Refl -> cong @_ @_ @((:$$) (what should i pass here...i don't really understand :$$))
it seems like I could just use elimNat
again, but I am not sure. I get these errors that I am not sure how to solve:
$(genDefunSymbols [''TypeClassInduction])
results in
Expected kind ‘* -> Constraint’, but ‘t0’ has kind ‘* -> *’
removing it results genDefunSymbols
in
Expected a type, but
‘TypeClassInduction a n f t’ has kind
‘Constraint’
This is understandable since I am not returning a type, but instead a constraint. Is there a way to solve this?
(also, forall xs x. (t (f xs), t x) => t (f (x ': xs))
is not valid haskell...but it seemed natural to write)
Edit:
replicateSucc is defined as
axiom :: a :~: b
axiom = unsafeCoerce Refl
replicateSucc :: forall k a. Replicate (k :+ 1) a :~: (a : Replicate k a)
replicateSucc = axiom