Skip to content

Refactor Template Haskell syntax conversions

On TemplateHaskell/Conversions there is a proposed refactoring of the Tempate Haskell-related syntax conversions. This task is to do that refactoring.

Edit: link.


Amendment by @sgraf812:

Concretely, we have (the wiki page is for Dec, but Type is nice and concrete)

  1. GHC.Tc.Gen.Splice.reifyType :: Core.Type -> TcM TH.Type
  2. GHC.HsToCore.Quote.repTy :: HsType GhcRn -> MetaM (Core (M TH.Type)) (where MetaM ~= ReaderT _ TcM)
  3. GHC.ThToHs.convertToHsType :: ... -> TH.Type -> Either _ (LHsType GhcPs)

It would be nice to factor

  • reifyType (1) into reifyType1 :: Core.Type -> TcM (HsType GhcRn) for haddock (SG: I don't know how up-to-date this is) and hsToTh :: HsType GhcRn -> TH.Type
  • repTy into the same hsToTh :: HsType GhcRn -> TH.Type and repThTy :: TH.Type -> MetaM (Core (M TH.Type))
  • Now the implementation of repTy1 is entirely mechanical and can be derived with TH! It is quite like Lift TH.Type, but it lives in MetaM and generates Core instead of a quote.

The same refactoring applies to Exp etc. I think this would yield an enormous simplification of GHC.HsToCore.Quote.

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