Unexpected kind error with type family and phantom datatype
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RoleAnnotations #-}
class ToList l where
type Item l
toList :: l -> [Item l]
type role Foo nominal
data Foo a = Foo -- a
instance ToList (Foo a) where
type Item (Foo a) = a
toList Foo = []
Error:
Expected a type, but ‘a’ has kind ‘k’ ‘k’ is a rigid type variable bound by a family instance declaration
Explicit role specification of the type parameter doesn't affect anything. Once Foo is redefined as follows
data Foo a = Foo a
The error disappears.
GHC 9.2.4