-tc_mkRep0TyCon :: TyCon -- The type to generate representation for
- -> MetaTyCons -- Metadata datatypes to refer to
- -> TcM TyCon -- Generated representation0 type
-tc_mkRep0TyCon tycon metaDts =
--- Consider the example input tycon `D`, where data D a b = D_ a
- do
- uniq1 <- newUnique
- uniq2 <- newUnique
- -- `rep0Ty` = D1 ... (C1 ... (S1 ... (Rec0 a))) :: * -> *
- rep0Ty <- tc_mkRep0Ty tycon metaDts
- -- `rep0` = GHC.Generics.Rep0 (type family)
- rep0 <- tcLookupTyCon rep0TyConName
-
- let modl = nameModule (tyConName tycon)
- loc = nameSrcSpan (tyConName tycon)
- -- `repName` is a name we generate for the synonym
- repName = mkExternalName uniq1 modl (mkGenR0 (nameOccName (tyConName tycon))) loc
- -- `coName` is a name for the coercion
- coName = mkExternalName uniq2 modl (mkGenR0 (nameOccName (tyConName tycon))) loc
- -- `tyvars` = [a,b]
- tyvars = tyConTyVars tycon
- -- `appT` = D a b
- appT = [mkTyConApp tycon (mkTyVarTys tyvars)]
- -- Result
- res = mkSynTyCon repName
- -- rep0Ty has kind `kind of D` -> *
- (tyConKind tycon `mkArrowKind` liftedTypeKind)
- tyvars (SynonymTyCon rep0Ty)
- (FamInstTyCon rep0 appT
- (mkCoercionTyCon coName (tyConArity tycon)
- -- co : forall a b. Rep0 (D a b) ~ `rep0Ty` a b
- (CoAxiom tyvars (mkTyConApp rep0 appT) rep0Ty)))
-
- return res
-