hypertypes icon indicating copy to clipboard operation
hypertypes copied to clipboard

Deriving HNodes (and friends) fails in the presence of PolyKinds

Open expipiplus1 opened this issue 1 year ago • 0 comments

data Foo x h = Foo (h :# Foo x)
makeHNodes ''Foo
error: [GHC-83865]
    • Couldn't match kind ‘*’ with ‘AHyperType -> *’
      Expected kind ‘HyperType’, but ‘Foo k_a33nj x_a338w’ has kind ‘*’
    • In the first argument of ‘HNodes’, namely ‘(Foo k_a33nj x_a338w)’
      In the instance declaration for ‘HNodes (Foo k_a33nj x_a338w)’
   |
73 | makeHNodes ''Foo
   | ^^^^^^^^^^^^^^^^

the expansion:

instance HNodes (Foo k_a35oD x_a35ah) where
  type
    forall constraint.
      HNodesConstraint (Foo k_a35oD x_a35ah) constraint =
        Solo
          constraint
          (Foo x_a35ah)
  type HWitnessType (Foo k_a35oD x_a35ah) = W_Foo k_a35oD x_a35ah
  {-# INLINE hLiftConstraint #-}
  hLiftConstraint (HWitness W_Foo_Foo_x) = \_ r_a3727 -> r_a3727

data W_Foo (k_a35oD :: Kind.Type) (x_a35ah :: k_a35oD) node where
  W_Foo_Foo_x :: W_Foo k_a35oD x_a35ah (Foo x_a35ah)
)

the corrected expansion (the kind signatures and kind variables removed)

instance HNodes (Foo x_a35ah) where
  type
    forall constraint.
      HNodesConstraint (Foo x_a35ah) constraint =
          constraint
          (Foo x_a35ah)
  type HWitnessType (Foo x_a35ah) = W_Foo x_a35ah
  {-# INLINE hLiftConstraint #-}
  hLiftConstraint (HWitness W_Foo_Foo_x) = \_ r_a3727 -> r_a3727

data W_Foo  x_a35ah node where
  W_Foo_Foo_x :: W_Foo x_a35ah (Foo x_a35ah)

expipiplus1 avatar Sep 19 '24 12:09 expipiplus1