Skip to content

Reification of primitive equality

When I reify (~~), I get something that looks like

class a ~ b => GHC.Types.~~ (a :: k0) (b :: k1)

This is wrong in at least two ways:

  1. ~ is homogeneous, so this is ill-kinded
  2. The superclass of ~~ is ~#, not ~.

I think we should just fail if we try to reify ~# or R#. But we don't. Instead, look at this:

reify_tc_app :: TyCon -> [Type.Type] -> TcM TH.Type
reify_tc_app tc tys
  = do { tys' <- reifyTypes (filterOutInvisibleTypes tc tys)
       ; maybe_sig_t (mkThAppTs r_tc tys') }
  where
    arity       = tyConArity tc

    r_tc | isUnboxedSumTyCon tc           = TH.UnboxedSumT (arity `div` 2)
         | isUnboxedTupleTyCon tc         = TH.UnboxedTupleT (arity `div` 2)
         | isPromotedTupleTyCon tc        = TH.PromotedTupleT (arity `div` 2)
             -- See Note [Unboxed tuple RuntimeRep vars] in TyCon
         | isTupleTyCon tc                = if isPromotedDataCon tc
                                            then TH.PromotedTupleT arity
                                            else TH.TupleT arity
         | tc `hasKey` constraintKindTyConKey
                                          = TH.ConstraintT
         | tc `hasKey` funTyConKey        = TH.ArrowT
         | tc `hasKey` listTyConKey       = TH.ListT
         | tc `hasKey` nilDataConKey      = TH.PromotedNilT
         | tc `hasKey` consDataConKey     = TH.PromotedConsT
         | tc `hasKey` heqTyConKey        = TH.EqualityT
         | tc `hasKey` eqPrimTyConKey     = TH.EqualityT
         | tc `hasKey` eqReprPrimTyConKey = TH.ConT (reifyName coercibleTyCon)
         | isPromotedDataCon tc           = TH.PromotedT (reifyName tc)
         | otherwise                      = TH.ConT (reifyName tc)

This erroneously maps the heterogeneous heqTyCon (that is, ~~) to EqualityT (presumably homogeneous -- indeed, it maps to ~ in ThToHs), along with strangely mapping primitive equality to lifted versions. And it doesn't detect ~ at all! Indeed, reifying ~ gives us GHC.Types.~.

This is all terrible. Can we fix? I propose erroring (with a nice, user-facing error message) on primitive equality, and not treating ~~ specially at all.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information