Skip to content

Representation-polymorphic HasField (fixes #22156)

Adam Gundry requested to merge wip/amg/T22156 into master

This generalises the HasField class to support representation polymorphism, so that instead of

type HasField :: forall {k} . k -> Type -> Type -> Constraint

we have

type HasField :: forall {k} {r_rep} {a_rep} . k -> TYPE r_rep -> TYPE a_rep -> Constraint

This change was approved by the CLC here: https://github.com/haskell/core-libraries-committee/issues/194#issuecomment-1800412006

The required code changes were surprisingly small. However, a small wrinkle is that this change makes GHC.Records no longer inferred as Safe due to the new import of TYPE from GHC.Exts. As far as I know TYPE is not currently exported from a Trustworthy module, so I've resorted to marking GHC.Records as Trustworthy. I don't know if there is a better solution here. EDIT: this happened anyway with the ghc-internal split, and I don't think it is particularly specific to GHC.Records anyway.

Edited by Adam Gundry

Merge request reports