X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypes%2FCoercion.lhs;h=ff49a6ef2b3ee5262face93ed9a8838377dcd640;hb=27897431cf24d4bde04b15947440c7205f2d703c;hp=25d04ecd249eab0ed571018ceffb19e4ca5c0904;hpb=fadef64b512886b6fe01b87fd2cd07fd952ab662;p=ghc-hetmet.git diff --git a/compiler/types/Coercion.lhs b/compiler/types/Coercion.lhs index 25d04ec..ff49a6e 100644 --- a/compiler/types/Coercion.lhs +++ b/compiler/types/Coercion.lhs @@ -22,7 +22,7 @@ module Coercion ( mkSymCoercion, mkTransCoercion, mkLeftCoercion, mkRightCoercion, mkInstCoercion, mkAppCoercion, mkForAllCoercion, mkFunCoercion, mkInstsCoercion, mkUnsafeCoercion, - mkNewTypeCoercion, mkAppsCoercion, + mkNewTypeCoercion, mkDataInstCoercion, mkAppsCoercion, splitNewTypeRepCo_maybe, decomposeCo, @@ -38,9 +38,9 @@ import Type ( Type, Kind, PredType, substTyWith, mkAppTy, mkForAllTy, mkFunTy, splitAppTy_maybe, splitForAllTy_maybe, coreView, kindView, mkTyConApp, isCoercionKind, isEqPred, mkAppTys, coreEqType, splitAppTys, isTyVarTy, splitTyConApp_maybe, - tyVarsOfType + tyVarsOfType, mkTyVarTys ) -import TyCon ( TyCon, tyConArity, mkCoercionTyCon, isNewTyCon, +import TyCon ( TyCon, tyConArity, mkCoercionTyCon, isClosedNewTyCon, newTyConRhs, newTyConCo, isCoercionTyCon, isCoercionTyCon_maybe ) import Var ( Var, TyVar, isTyVar, tyVarKind ) @@ -323,7 +323,31 @@ mkNewTypeCoercion name tycon tvs rhs_ty rhs_eta | (ty, ty_args) <- splitAppTys rhs_ty = mkAppTys ty (reverse (drop n_eta_tys (reverse ty_args))) - + +-- Coercion identifying a data/newtype representation type and its family +-- instance. It has the form `Co tvs :: F ts :=: R tvs', where `Co' is the +-- coercion tycon built here, `F' the family tycon and `R' the (derived) +-- representation tycon. +-- +mkDataInstCoercion :: Name -- unique name for the coercion tycon + -> [TyVar] -- type parameters of the coercion (`tvs') + -> TyCon -- family tycon (`F') + -> [Type] -- type instance (`ts') + -> TyCon -- representation tycon (`R') + -> TyCon -- => coercion tycon (`Co') +mkDataInstCoercion name tvs family instTys rep_tycon + = mkCoercionTyCon name coArity (mkKindingFun rule) + where + coArity = length tvs + + rule args = (substTyWith tvs tys $ -- with sigma = [tys/tvs], + TyConApp family instTys, -- sigma (F ts) + TyConApp rep_tycon tys, -- :=: R tys + rest) -- surplus arguments + where + tys = take coArity args + rest = drop coArity args + -------------------------------------- -- Coercion Type Constructors... @@ -427,7 +451,7 @@ splitNewTypeRepCo_maybe :: Type -> Maybe (Type, Coercion) splitNewTypeRepCo_maybe ty | Just ty' <- coreView ty = splitNewTypeRepCo_maybe ty' splitNewTypeRepCo_maybe (TyConApp tc tys) - | isNewTyCon tc + | isClosedNewTyCon tc = ASSERT( tys `lengthIs` tyConArity tc ) -- splitNewTypeRepCo_maybe only be applied -- to *types* (of kind *) case newTyConRhs tc of