Commit a17d3295 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Rename isIdentityCoercion to isIdentityCoI; add Coercion.isIdentityCoercion

parent 678086d0
......@@ -812,7 +812,7 @@ unifyCtxts (sig1 : sigs) -- Argument is always non-empty
-- where F is a type function and (F a ~ [a])
-- Then unification might succeed with a coercion. But it's much
-- much simpler to require that such signatures have identical contexts
checkTc (all isIdentityCoercion cois)
checkTc (all isIdentityCoI cois)
(ptext (sLit "Mutually dependent functions have syntactically distinct contexts"))
}
......
......@@ -427,7 +427,7 @@ tc_pat pstate (orig@(ViewPat expr pat _)) overall_pat_ty thing_inside
tc_pat pstate (SigPatIn pat sig_ty) pat_ty thing_inside
= do { (inner_ty, tv_binds, coi) <- tcPatSig (patSigCtxt pstate) sig_ty
pat_ty
; unless (isIdentityCoercion coi) $
; unless (isIdentityCoI coi) $
failWithTc (badSigPat pat_ty)
; (pat', tvs, res) <- tcExtendTyVarEnv2 tv_binds $
tc_lpat pat inner_ty pstate thing_inside
......@@ -702,7 +702,7 @@ tcConPat pstate con_span data_con tycon pat_ty arg_pats thing_inside
; (_, freshTvs, subst) <- tcInstTyVars (tyConTyVars tycon)
; let instTys' = substTys subst instTys
; cois <- boxyUnifyList instTys' scrutinee_arg_tys
; let coi = if isIdentityCoercion coi1
; let coi = if isIdentityCoI coi1
then -- pat_ty was splittable
-- => boxyUnifyList had real work to do
mkTyConAppCoI fam_tycon instTys' cois
......
......@@ -22,7 +22,7 @@ module Coercion (
Coercion,
mkCoKind, mkReflCoKind, splitCoercionKind_maybe, splitCoercionKind,
coercionKind, coercionKinds, coercionKindPredTy,
coercionKind, coercionKinds, coercionKindPredTy, isIdentityCoercion,
-- ** Equality predicates
isEqPred, mkEqPred, getEqPredTys, isEqPredTy,
......@@ -46,7 +46,7 @@ module Coercion (
-- * CoercionI
CoercionI(..),
isIdentityCoercion,
isIdentityCoI,
mkSymCoI, mkTransCoI,
mkTyConAppCoI, mkAppTyCoI, mkFunTyCoI,
mkForAllTyCoI,
......@@ -183,6 +183,12 @@ coercionKindPredTy c = let (t1, t2) = coercionKind c in mkCoKind t1 t2
coercionKinds :: [Coercion] -> ([Type], [Type])
coercionKinds tys = unzip $ map coercionKind tys
-------------------------------------
isIdentityCoercion :: Coercion -> Bool
isIdentityCoercion co
= case coercionKind co of
(t1,t2) -> t1 `coreEqType` t2
-------------------------------------
-- Coercion kind and type mk's
-- (make saturated TyConApp CoercionTyCon{...} args)
......@@ -580,13 +586,13 @@ instance Outputable CoercionI where
ppr IdCo = ptext (sLit "IdCo")
ppr (ACo co) = ppr co
isIdentityCoercion :: CoercionI -> Bool
isIdentityCoercion IdCo = True
isIdentityCoercion _ = False
isIdentityCoI :: CoercionI -> Bool
isIdentityCoI IdCo = True
isIdentityCoI _ = False
-- | Tests whether all the given 'CoercionI's represent the identity coercion
allIdCos :: [CoercionI] -> Bool
allIdCos = all isIdentityCoercion
allIdCoIs :: [CoercionI] -> Bool
allIdCoIs = all isIdentityCoI
-- | For each 'CoercionI' in the input list, return either the 'Coercion' it
-- contains or the corresponding 'Type' from the other list
......@@ -615,8 +621,8 @@ mkTransCoI (ACo co1) (ACo co2) = ACo $ mkTransCoercion co1 co2
-- | Smart constructor for type constructor application on 'CoercionI', see also 'mkAppCoercion'
mkTyConAppCoI :: TyCon -> [Type] -> [CoercionI] -> CoercionI
mkTyConAppCoI tyCon tys cois
| allIdCos cois = IdCo
| otherwise = ACo (TyConApp tyCon (zipCoArgs cois tys))
| allIdCoIs cois = IdCo
| otherwise = ACo (TyConApp tyCon (zipCoArgs cois tys))
-- | Smart constructor for honest-to-god 'Coercion' application on 'CoercionI', see also 'mkAppCoercion'
mkAppTyCoI :: Type -> CoercionI -> Type -> CoercionI -> CoercionI
......@@ -645,8 +651,8 @@ fromACo (ACo co) = co
-- > mkClassPPredCoI cls tys cois :: PredTy (cls tys) ~ PredTy (cls (tys `cast` cois))
mkClassPPredCoI :: Class -> [Type] -> [CoercionI] -> CoercionI
mkClassPPredCoI cls tys cois
| allIdCos cois = IdCo
| otherwise = ACo $ PredTy $ ClassP cls (zipCoArgs cois tys)
| allIdCoIs cois = IdCo
| otherwise = ACo $ PredTy $ ClassP cls (zipCoArgs cois tys)
-- | Smart constructor for implicit parameter 'Coercion's on 'CoercionI'. Similar to 'mkClassPPredCoI'
mkIParamPredCoI :: (IPName Name) -> CoercionI -> CoercionI
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment