X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FInst.lhs;h=cada794388baf4aace9f23eded36348fd099276b;hb=3517c53d8a66149dcc3f971cf0577719e99d6d70;hp=8a014bca6f6db9f0b2a27c4b7b6ab225daf52833;hpb=e5a8d57c85d42007c8cc561e6d6b805c23603fc0;p=ghc-hetmet.git diff --git a/compiler/typecheck/Inst.lhs b/compiler/typecheck/Inst.lhs index 8a014bc..cada794 100644 --- a/compiler/typecheck/Inst.lhs +++ b/compiler/typecheck/Inst.lhs @@ -42,6 +42,7 @@ module Inst ( mkWantedCo, mkGivenCo, isWantedCo, eqInstCoType, mkIdEqInstCo, mkSymEqInstCo, mkLeftTransEqInstCo, mkRightTransEqInstCo, mkAppEqInstCo, + mkTyConEqInstCo, mkFunEqInstCo, wantedEqInstIsUnsolved, eitherEqInst, mkEqInst, mkWantedEqInst, wantedToLocalEqInst, finalizeEqInst, eqInstType, eqInstCoercion, eqInstTys @@ -62,6 +63,7 @@ import FunDeps import TcMType import TcType import MkCore +import TyCon import Type import TypeRep import Class @@ -1076,6 +1078,36 @@ mkAppEqInstCo (Left cotv) (ty1_l, ty2_l) (ty1_r, ty2_r) } mkAppEqInstCo (Right co) _ _ = return (Right $ mkLeftCoercion co, Right $ mkRightCoercion co) + +-- Coercion transformation: co = con col -> cor +-- +mkTyConEqInstCo :: EqInstCo -> TyCon -> [(Type, Type)] -> TcM ([EqInstCo]) +mkTyConEqInstCo (Left cotv) con ty12s + = do { cotvs <- mapM (uncurry newMetaCoVar) ty12s + ; writeMetaTyVar cotv (mkTyConCoercion con (mkTyVarTys cotvs)) + ; return (map Left cotvs) + } +mkTyConEqInstCo (Right co) _ args + = return $ map (\mkCoes -> Right $ foldl (.) id mkCoes co) mkCoes + -- make cascades of the form + -- mkRightCoercion (mkLeftCoercion .. (mkLeftCoercion co)..) + where + n = length args + mkCoes = [mkRightCoercion : replicate i mkLeftCoercion | i <- [n-1, n-2..0]] + +-- Coercion transformation: co = col -> cor +-- +mkFunEqInstCo :: EqInstCo -> (Type, Type) -> (Type, Type) + -> TcM (EqInstCo, EqInstCo) +mkFunEqInstCo (Left cotv) (ty1_l, ty2_l) (ty1_r, ty2_r) + = do { cotv_l <- newMetaCoVar ty1_l ty2_l + ; cotv_r <- newMetaCoVar ty1_r ty2_r + ; writeMetaTyVar cotv (mkFunCoercion (TyVarTy cotv_l) (TyVarTy cotv_r)) + ; return (Left cotv_l, Left cotv_r) + } +mkFunEqInstCo (Right co) _ _ + = return (Right $ mkRightCoercion (mkLeftCoercion co), + Right $ mkRightCoercion co) \end{code} Operations on entire EqInst.