Skip to content

Invisible binders in type declarations (#22560)

Vladislav Zavialov requested to merge wip/int-index/decl-invis-binders into master

This patch implements @k-binders introduced in GHC Proposal #425 and guarded behind the TypeAbstractions extension:

data D @k @j (a :: k) (b :: j) = ...
       ^^ ^^

To represent the new syntax, we modify LHsQTyVars as follows:

-  hsq_explicit :: [LHsTyVarBndr () pass]
+  hsq_explicit :: [LHsTyVarBndr (HsBndrVis pass) pass]

HsBndrVis is a new data type that records the distinction between type variable binders written with and without the @ sign:

data HsBndrVis pass
  = HsBndrRequired
  | HsBndrInvisible (LHsToken "@" pass)

The rest of the patch updates GHC, template-haskell, and haddock to handle the new syntax.

Parser. The PsErrUnexpectedTypeAppInDecl error message is removed. This syntax is now permitted.

Renamer. The @ sign does not affect the scope of a binder, so the changes to the renamer are minimal. See rnLHsTyVarBndrVisFlag.

Type checker. There are three code paths that were updated to deal with the newly introduced invisible type variable binders:

  1. checking SAKS: see kcCheckDeclHeader_sig, matchUpSigWithDecl
  2. checking CUSK: see kcCheckDeclHeader_cusk
  3. inference: see kcInferDeclHeader, generaliseTcTyCon

Helper functions bindExplicitTKBndrs_Q_Skol and bindExplicitTKBndrs_Q_Tv are generalized to work with HsBndrVis.

Edited by Vladislav Zavialov

Merge request reports