X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypes%2FTypeRep.lhs;h=69ee4194396062d2216c2406739ef155c0d2718d;hb=14ddfba2df68917958afb54142bb609c66fa2110;hp=2fe5954a15c44c2c9c71c0ef53e1903304d41acc;hpb=ad94d40948668032189ad22a0ad741ac1f645f50;p=ghc-hetmet.git diff --git a/compiler/types/TypeRep.lhs b/compiler/types/TypeRep.lhs index 2fe5954..69ee419 100644 --- a/compiler/types/TypeRep.lhs +++ b/compiler/types/TypeRep.lhs @@ -9,7 +9,7 @@ -- The above warning supression flag is a temporary kludge. -- While working on this module you are encouraged to remove it and fix -- any warnings in the module. See --- http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings -- for details module TypeRep ( @@ -23,7 +23,7 @@ module TypeRep ( -- Pretty-printing pprType, pprParendType, pprTypeApp, - pprTyThingCategory, + pprTyThing, pprTyThingCategory, pprPred, pprTheta, pprForAll, pprThetaArrow, pprClassPred, -- Kinds @@ -31,6 +31,7 @@ module TypeRep ( argTypeKind, ubxTupleKind, isLiftedTypeKindCon, isLiftedTypeKind, mkArrowKind, mkArrowKinds, isCoercionKind, + coVarPred, -- Kind constructors... liftedTypeKindTyCon, openTypeKindTyCon, unliftedTypeKindTyCon, @@ -292,8 +293,11 @@ data TyThing = AnId Id | ATyCon TyCon | AClass Class -instance Outputable TyThing where - ppr thing = pprTyThingCategory thing <+> quotes (ppr (getName thing)) +instance Outputable TyThing where + ppr = pprTyThing + +pprTyThing :: TyThing -> SDoc +pprTyThing thing = pprTyThingCategory thing <+> quotes (ppr (getName thing)) pprTyThingCategory :: TyThing -> SDoc pprTyThingCategory (ATyCon _) = ptext SLIT("Type constructor") @@ -409,6 +413,13 @@ isCoercionKind :: Kind -> Bool isCoercionKind (NoteTy _ k) = isCoercionKind k isCoercionKind (PredTy (EqPred {})) = True isCoercionKind other = False + +coVarPred :: CoVar -> PredType +coVarPred tv + = ASSERT( isCoVar tv ) + case tyVarKind tv of + PredTy eq -> eq -- There shouldn't even be a NoteTy in the way + other -> pprPanic "coVarPred" (ppr tv $$ ppr other) \end{code} @@ -481,7 +492,7 @@ pprParendKind = pprParendType ppr_type :: Prec -> Type -> SDoc ppr_type p (TyVarTy tv) = ppr tv ppr_type p (PredTy pred) = ifPprDebug (ptext SLIT("")) <> (ppr pred) -ppr_type p (NoteTy other ty2) = ppr_type p ty2 +ppr_type p (NoteTy other ty2) = ifPprDebug (ptext SLIT("")) <> ppr_type p ty2 ppr_type p (TyConApp tc tys) = ppr_tc_app p tc tys ppr_type p (AppTy t1 t2) = maybeParen p TyConPrec $ @@ -506,15 +517,22 @@ ppr_forall_type p ty (tvs, rho) = split1 [] ty (ctxt, tau) = split2 [] rho - split1 tvs (ForAllTy tv ty) = split1 (tv:tvs) ty - split1 tvs (NoteTy _ ty) = split1 tvs ty - split1 tvs ty = (reverse tvs, ty) + -- We need to be extra careful here as equality constraints will occur as + -- type variables with an equality kind. So, while collecting quantified + -- variables, we separate the coercion variables out and turn them into + -- equality predicates. + split1 tvs (ForAllTy tv ty) + | not (isCoVar tv) = split1 (tv:tvs) ty + split1 tvs (NoteTy _ ty) = split1 tvs ty + split1 tvs ty = (reverse tvs, ty) split2 ps (NoteTy _ arg -- Rather a disgusting case - `FunTy` res) = split2 ps (arg `FunTy` res) - split2 ps (PredTy p `FunTy` ty) = split2 (p:ps) ty - split2 ps (NoteTy _ ty) = split2 ps ty - split2 ps ty = (reverse ps, ty) + `FunTy` res) = split2 ps (arg `FunTy` res) + split2 ps (PredTy p `FunTy` ty) = split2 (p:ps) ty + split2 ps (ForAllTy tv ty) + | isCoVar tv = split2 (coVarPred tv : ps) ty + split2 ps (NoteTy _ ty) = split2 ps ty + split2 ps ty = (reverse ps, ty) ppr_tc_app :: Prec -> TyCon -> [Type] -> SDoc ppr_tc_app p tc []