Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Module for (a) type kinds and (b) type coercions,
as used in System FC. See Expr
for
more on System FC and how coercions fit into it.
Synopsis
- data Coercion
- type CoercionN = Coercion
- type CoercionR = Coercion
- type CoercionP = Coercion
- data MCoercion
- type MCoercionN = MCoercion
- type MCoercionR = MCoercion
- data UnivCoProvenance
- data CoercionHole = CoercionHole {}
- coHoleCoVar :: CoercionHole -> CoVar
- setCoHoleCoVar :: CoercionHole -> CoVar -> CoercionHole
- data LeftOrRight
- data Var
- type CoVar = Id
- type TyCoVar = Id
- data Role
- ltRole :: Role -> Role -> Bool
- coVarTypes :: HasDebugCallStack => CoVar -> Pair Type
- coVarKind :: CoVar -> Type
- coVarKindsTypesRole :: HasDebugCallStack => CoVar -> (Kind, Kind, Type, Type, Role)
- coVarRole :: CoVar -> Role
- coercionType :: Coercion -> Type
- mkCoercionType :: Role -> Type -> Type -> Type
- coercionKind :: Coercion -> Pair Type
- coercionLKind :: Coercion -> Type
- coercionRKind :: Coercion -> Type
- coercionKinds :: [Coercion] -> Pair [Type]
- coercionRole :: Coercion -> Role
- coercionKindRole :: Coercion -> (Pair Type, Role)
- mkGReflCo :: Role -> Type -> MCoercionN -> Coercion
- mkReflCo :: Role -> Type -> Coercion
- mkRepReflCo :: Type -> Coercion
- mkNomReflCo :: Type -> Coercion
- mkCoVarCo :: CoVar -> Coercion
- mkCoVarCos :: [CoVar] -> [Coercion]
- mkAxInstCo :: Role -> CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Coercion
- mkUnbranchedAxInstCo :: Role -> CoAxiom Unbranched -> [Type] -> [Coercion] -> Coercion
- mkAxInstRHS :: CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Type
- mkUnbranchedAxInstRHS :: CoAxiom Unbranched -> [Type] -> [Coercion] -> Type
- mkAxInstLHS :: CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Type
- mkUnbranchedAxInstLHS :: CoAxiom Unbranched -> [Type] -> [Coercion] -> Type
- mkPiCo :: Role -> Var -> Coercion -> Coercion
- mkPiCos :: Role -> [Var] -> Coercion -> Coercion
- mkCoCast :: Coercion -> CoercionR -> Coercion
- mkSymCo :: Coercion -> Coercion
- mkTransCo :: Coercion -> Coercion -> Coercion
- mkNthCo :: HasDebugCallStack => Role -> Int -> Coercion -> Coercion
- mkNthCoFunCo :: Int -> CoercionN -> Coercion -> Coercion -> Coercion
- nthCoRole :: Int -> Coercion -> Role
- mkLRCo :: LeftOrRight -> Coercion -> Coercion
- mkInstCo :: Coercion -> Coercion -> Coercion
- mkAppCo :: Coercion -> Coercion -> Coercion
- mkAppCos :: Coercion -> [Coercion] -> Coercion
- mkTyConAppCo :: HasDebugCallStack => Role -> TyCon -> [Coercion] -> Coercion
- mkFunCo :: Role -> CoercionN -> Coercion -> Coercion -> Coercion
- mkFunResCo :: Role -> Scaled Type -> Coercion -> Coercion
- mkForAllCo :: TyCoVar -> CoercionN -> Coercion -> Coercion
- mkForAllCos :: [(TyCoVar, CoercionN)] -> Coercion -> Coercion
- mkHomoForAllCos :: [TyCoVar] -> Coercion -> Coercion
- mkPhantomCo :: Coercion -> Type -> Type -> Coercion
- mkHoleCo :: CoercionHole -> Coercion
- mkUnivCo :: UnivCoProvenance -> Role -> Type -> Type -> Coercion
- mkSubCo :: HasDebugCallStack => Coercion -> Coercion
- mkAxiomInstCo :: CoAxiom Branched -> BranchIndex -> [Coercion] -> Coercion
- mkProofIrrelCo :: Role -> Coercion -> Coercion -> Coercion -> Coercion
- downgradeRole :: Role -> Role -> Coercion -> Coercion
- mkAxiomRuleCo :: CoAxiomRule -> [Coercion] -> Coercion
- mkGReflRightCo :: Role -> Type -> CoercionN -> Coercion
- mkGReflLeftCo :: Role -> Type -> CoercionN -> Coercion
- mkCoherenceLeftCo :: Role -> Type -> CoercionN -> Coercion -> Coercion
- mkCoherenceRightCo :: Role -> Type -> CoercionN -> Coercion -> Coercion
- mkKindCo :: Coercion -> Coercion
- castCoercionKind :: Coercion -> CoercionN -> CoercionN -> Coercion
- castCoercionKind1 :: Coercion -> Role -> Type -> Type -> CoercionN -> Coercion
- castCoercionKind2 :: Coercion -> Role -> Type -> Type -> CoercionN -> CoercionN -> Coercion
- mkFamilyTyConAppCo :: TyCon -> [CoercionN] -> CoercionN
- mkHeteroCoercionType :: Role -> Kind -> Kind -> Type -> Type -> Type
- mkPrimEqPred :: Type -> Type -> Type
- mkReprPrimEqPred :: Type -> Type -> Type
- mkPrimEqPredRole :: Role -> Type -> Type -> PredType
- mkHeteroPrimEqPred :: Kind -> Kind -> Type -> Type -> Type
- mkHeteroReprPrimEqPred :: Kind -> Kind -> Type -> Type -> Type
- instNewTyCon_maybe :: TyCon -> [Type] -> Maybe (Type, Coercion)
- type NormaliseStepper ev = RecTcChecker -> TyCon -> [Type] -> NormaliseStepResult ev
- data NormaliseStepResult ev
- = NS_Done
- | NS_Abort
- | NS_Step RecTcChecker Type ev
- composeSteppers :: NormaliseStepper ev -> NormaliseStepper ev -> NormaliseStepper ev
- mapStepResult :: (ev1 -> ev2) -> NormaliseStepResult ev1 -> NormaliseStepResult ev2
- unwrapNewTypeStepper :: NormaliseStepper Coercion
- topNormaliseNewType_maybe :: Type -> Maybe (Coercion, Type)
- topNormaliseTypeX :: NormaliseStepper ev -> (ev -> ev -> ev) -> Type -> Maybe (ev, Type)
- decomposeCo :: Arity -> Coercion -> [Role] -> [Coercion]
- decomposeFunCo :: HasDebugCallStack => Role -> Coercion -> (CoercionN, Coercion, Coercion)
- decomposePiCos :: HasDebugCallStack => CoercionN -> Pair Type -> [Type] -> ([CoercionN], CoercionN)
- getCoVar_maybe :: Coercion -> Maybe CoVar
- splitTyConAppCo_maybe :: Coercion -> Maybe (TyCon, [Coercion])
- splitAppCo_maybe :: Coercion -> Maybe (Coercion, Coercion)
- splitFunCo_maybe :: Coercion -> Maybe (Coercion, Coercion)
- splitForAllCo_maybe :: Coercion -> Maybe (TyCoVar, Coercion, Coercion)
- splitForAllCo_ty_maybe :: Coercion -> Maybe (TyVar, Coercion, Coercion)
- splitForAllCo_co_maybe :: Coercion -> Maybe (CoVar, Coercion, Coercion)
- nthRole :: Role -> TyCon -> Int -> Role
- tyConRolesX :: Role -> TyCon -> [Role]
- tyConRolesRepresentational :: TyCon -> [Role]
- setNominalRole_maybe :: Role -> Coercion -> Maybe Coercion
- pickLR :: LeftOrRight -> (a, a) -> a
- isGReflCo :: Coercion -> Bool
- isReflCo :: Coercion -> Bool
- isReflCo_maybe :: Coercion -> Maybe (Type, Role)
- isGReflCo_maybe :: Coercion -> Maybe (Type, Role)
- isReflexiveCo :: Coercion -> Bool
- isReflexiveCo_maybe :: Coercion -> Maybe (Type, Role)
- isReflCoVar_maybe :: Var -> Maybe Coercion
- isGReflMCo :: MCoercion -> Bool
- mkGReflLeftMCo :: Role -> Type -> MCoercionN -> Coercion
- mkGReflRightMCo :: Role -> Type -> MCoercionN -> Coercion
- mkCoherenceRightMCo :: Role -> Type -> MCoercionN -> Coercion -> Coercion
- coToMCo :: Coercion -> MCoercion
- mkTransMCo :: MCoercion -> MCoercion -> MCoercion
- mkTransMCoL :: MCoercion -> Coercion -> MCoercion
- mkTransMCoR :: Coercion -> MCoercion -> MCoercion
- mkCastTyMCo :: Type -> MCoercion -> Type
- mkSymMCo :: MCoercion -> MCoercion
- mkHomoForAllMCo :: TyCoVar -> MCoercion -> MCoercion
- mkFunResMCo :: Scaled Type -> MCoercionR -> MCoercionR
- mkPiMCos :: [Var] -> MCoercion -> MCoercion
- checkReflexiveMCo :: MCoercion -> MCoercion
- isReflMCo :: MCoercion -> Bool
- mkCoVar :: Name -> Type -> CoVar
- isCoVar :: Var -> Bool
- coVarName :: CoVar -> Name
- setCoVarName :: CoVar -> Name -> CoVar
- setCoVarUnique :: CoVar -> Unique -> CoVar
- isCoVar_maybe :: Coercion -> Maybe CoVar
- tyCoVarsOfCo :: Coercion -> TyCoVarSet
- tyCoVarsOfCos :: [Coercion] -> TyCoVarSet
- coVarsOfCo :: Coercion -> CoVarSet
- tyCoFVsOfCo :: Coercion -> FV
- tyCoFVsOfCos :: [Coercion] -> FV
- tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet
- coercionSize :: Coercion -> Int
- anyFreeVarsOfCo :: (TyCoVar -> Bool) -> Coercion -> Bool
- type CvSubstEnv = CoVarEnv Coercion
- emptyCvSubstEnv :: CvSubstEnv
- lookupCoVar :: TCvSubst -> Var -> Maybe Coercion
- substCo :: HasCallStack => TCvSubst -> Coercion -> Coercion
- substCos :: HasCallStack => TCvSubst -> [Coercion] -> [Coercion]
- substCoVar :: TCvSubst -> CoVar -> Coercion
- substCoVars :: TCvSubst -> [CoVar] -> [Coercion]
- substCoWith :: HasCallStack => [TyVar] -> [Type] -> Coercion -> Coercion
- substCoVarBndr :: HasCallStack => TCvSubst -> CoVar -> (TCvSubst, CoVar)
- extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> TCvSubst
- getCvSubstEnv :: TCvSubst -> CvSubstEnv
- liftCoSubst :: HasDebugCallStack => Role -> LiftingContext -> Type -> Coercion
- liftCoSubstTyVar :: LiftingContext -> Role -> TyVar -> Maybe Coercion
- liftCoSubstWith :: Role -> [TyCoVar] -> [Coercion] -> Type -> Coercion
- liftCoSubstWithEx :: Role -> [TyVar] -> [Coercion] -> [TyCoVar] -> [Type] -> (Type -> Coercion, [Type])
- emptyLiftingContext :: InScopeSet -> LiftingContext
- extendLiftingContext :: LiftingContext -> TyCoVar -> Coercion -> LiftingContext
- extendLiftingContextAndInScope :: LiftingContext -> TyCoVar -> Coercion -> LiftingContext
- liftCoSubstVarBndrUsing :: (LiftingContext -> Type -> (CoercionN, a)) -> LiftingContext -> TyCoVar -> (LiftingContext, TyCoVar, CoercionN, a)
- isMappedByLC :: TyCoVar -> LiftingContext -> Bool
- mkSubstLiftingContext :: TCvSubst -> LiftingContext
- zapLiftingContext :: LiftingContext -> LiftingContext
- substForAllCoBndrUsingLC :: Bool -> (Coercion -> Coercion) -> LiftingContext -> TyCoVar -> Coercion -> (LiftingContext, TyCoVar, Coercion)
- lcTCvSubst :: LiftingContext -> TCvSubst
- lcInScopeSet :: LiftingContext -> InScopeSet
- type LiftCoEnv = VarEnv Coercion
- data LiftingContext = LC TCvSubst LiftCoEnv
- liftEnvSubstLeft :: TCvSubst -> LiftCoEnv -> TCvSubst
- liftEnvSubstRight :: TCvSubst -> LiftCoEnv -> TCvSubst
- substRightCo :: LiftingContext -> Coercion -> Coercion
- substLeftCo :: LiftingContext -> Coercion -> Coercion
- swapLiftCoEnv :: LiftCoEnv -> LiftCoEnv
- lcSubstLeft :: LiftingContext -> TCvSubst
- lcSubstRight :: LiftingContext -> TCvSubst
- eqCoercion :: Coercion -> Coercion -> Bool
- eqCoercionX :: RnEnv2 -> Coercion -> Coercion -> Bool
- seqCo :: Coercion -> ()
- pprCo :: Coercion -> SDoc
- pprParendCo :: Coercion -> SDoc
- pprCoAxiom :: CoAxiom br -> SDoc
- pprCoAxBranch :: TyCon -> CoAxBranch -> SDoc
- pprCoAxBranchLHS :: TyCon -> CoAxBranch -> SDoc
- pprCoAxBranchUser :: TyCon -> CoAxBranch -> SDoc
- tidyCoAxBndrsForUser :: TidyEnv -> [Var] -> (TidyEnv, [Var])
- etaExpandCoAxBranch :: CoAxBranch -> ([TyVar], [Type], Type)
- tidyCo :: TidyEnv -> Coercion -> Coercion
- tidyCos :: TidyEnv -> [Coercion] -> [Coercion]
- promoteCoercion :: Coercion -> CoercionN
- buildCoercion :: Type -> Type -> CoercionN
- multToCo :: Mult -> Coercion
- simplifyArgsWorker :: [TyCoBinder] -> Kind -> TyCoVarSet -> [Role] -> [(Type, Coercion)] -> ([Type], [Coercion], MCoercionN)
- hasCoercionHoleTy :: Type -> Bool
- hasCoercionHoleCo :: Coercion -> Bool
- type HoleSet = UniqSet CoercionHole
- coercionHolesOfType :: Type -> UniqSet CoercionHole
- coercionHolesOfCo :: Coercion -> UniqSet CoercionHole
Main data type
A Coercion
is concrete evidence of the equality/convertibility
of two types.
Instances
Data Coercion Source # | |
Defined in GHC.Core.TyCo.Rep gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Coercion -> c Coercion Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Coercion Source # toConstr :: Coercion -> Constr Source # dataTypeOf :: Coercion -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Coercion) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Coercion) Source # gmapT :: (forall b. Data b => b -> b) -> Coercion -> Coercion Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Coercion -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Coercion -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Coercion -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Coercion -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Coercion -> m Coercion Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Coercion -> m Coercion Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Coercion -> m Coercion Source # | |
Outputable Coercion Source # | |
Eq (DeBruijn Coercion) Source # | |
A semantically more meaningful type to represent what may or may not be a
useful Coercion
.
Instances
Data MCoercion Source # | |
Defined in GHC.Core.TyCo.Rep gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> MCoercion -> c MCoercion Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c MCoercion Source # toConstr :: MCoercion -> Constr Source # dataTypeOf :: MCoercion -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c MCoercion) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c MCoercion) Source # gmapT :: (forall b. Data b => b -> b) -> MCoercion -> MCoercion Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> MCoercion -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> MCoercion -> r Source # gmapQ :: (forall d. Data d => d -> u) -> MCoercion -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> MCoercion -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> MCoercion -> m MCoercion Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> MCoercion -> m MCoercion Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> MCoercion -> m MCoercion Source # | |
Outputable MCoercion Source # | |
type MCoercionN = MCoercion Source #
type MCoercionR = MCoercion Source #
data UnivCoProvenance Source #
For simplicity, we have just one UnivCo that represents a coercion from
some type to some other type, with (in general) no restrictions on the
type. The UnivCoProvenance specifies more exactly what the coercion really
is and why a program should (or shouldn't!) trust the coercion.
It is reasonable to consider each constructor of UnivCoProvenance
as a totally independent coercion form; their only commonality is
that they don't tell you what types they coercion between. (That info
is in the UnivCo
constructor of Coercion
.
Instances
data CoercionHole Source #
A coercion to be filled in by the type-checker. See Note [Coercion holes]
Instances
Data CoercionHole Source # | |
Defined in GHC.Core.TyCo.Rep gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CoercionHole -> c CoercionHole Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CoercionHole Source # toConstr :: CoercionHole -> Constr Source # dataTypeOf :: CoercionHole -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CoercionHole) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CoercionHole) Source # gmapT :: (forall b. Data b => b -> b) -> CoercionHole -> CoercionHole Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CoercionHole -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CoercionHole -> r Source # gmapQ :: (forall d. Data d => d -> u) -> CoercionHole -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> CoercionHole -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> CoercionHole -> m CoercionHole Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CoercionHole -> m CoercionHole Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CoercionHole -> m CoercionHole Source # | |
Uniquable CoercionHole Source # | |
Defined in GHC.Core.TyCo.Rep getUnique :: CoercionHole -> Unique Source # | |
Outputable CoercionHole Source # | |
Defined in GHC.Core.TyCo.Rep ppr :: CoercionHole -> SDoc Source # |
coHoleCoVar :: CoercionHole -> CoVar Source #
setCoHoleCoVar :: CoercionHole -> CoVar -> CoercionHole Source #
data LeftOrRight Source #
Instances
Variable
Essentially a typed Name
, that may also contain some additional information
about the Var
and its use sites.
Instances
Data Var Source # | |
Defined in GHC.Types.Var gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Var -> c Var Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Var Source # toConstr :: Var -> Constr Source # dataTypeOf :: Var -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Var) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var) Source # gmapT :: (forall b. Data b => b -> b) -> Var -> Var Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Var -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Var -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Var -> m Var Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source # | |
NamedThing Var Source # | |
HasOccName Var Source # | |
Uniquable Var Source # | |
Outputable Var Source # | |
OutputableBndr Var Source # | |
Defined in GHC.Core.Ppr | |
Eq Var Source # | |
Ord Var Source # | |
Eq (DeBruijn CoreAlt) Source # | |
Eq (DeBruijn CoreExpr) Source # | |
type Anno Id Source # | |
Defined in GHC.Hs.Extension | |
type Anno (LocatedN Id) Source # | |
Defined in GHC.Hs.Binds | |
type Anno [LocatedN Id] Source # | |
Defined in GHC.Hs.Binds |
Instances
Data Role Source # | |
Defined in GHC.Core.Coercion.Axiom gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Role -> c Role Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Role Source # toConstr :: Role -> Constr Source # dataTypeOf :: Role -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Role) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Role) Source # gmapT :: (forall b. Data b => b -> b) -> Role -> Role Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Role -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Role -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Role -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Role -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Role -> m Role Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Role -> m Role Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Role -> m Role Source # | |
Binary Role Source # | |
Outputable Role Source # | |
Eq Role Source # | |
Ord Role Source # | |
type Anno (Maybe Role) Source # | |
Defined in GHC.Hs.Decls | |
type Anno (Maybe Role) Source # | |
Defined in GHC.Hs.Decls |
Functions over coercions
coVarTypes :: HasDebugCallStack => CoVar -> Pair Type Source #
coVarKindsTypesRole :: HasDebugCallStack => CoVar -> (Kind, Kind, Type, Type, Role) Source #
coercionType :: Coercion -> Type Source #
mkCoercionType :: Role -> Type -> Type -> Type Source #
Makes a coercion type from two types: the types whose equality
is proven by the relevant Coercion
coercionKind :: Coercion -> Pair Type Source #
If it is the case that
c :: (t1 ~ t2)
i.e. the kind of c
relates t1
and t2
, then coercionKind c = Pair t1 t2
.
coercionLKind :: Coercion -> Type Source #
coercionRKind :: Coercion -> Type Source #
coercionKinds :: [Coercion] -> Pair [Type] Source #
Apply coercionKind
to multiple Coercion
s
coercionRole :: Coercion -> Role Source #
Retrieve the role from a coercion.
Constructing coercions
mkRepReflCo :: Type -> Coercion Source #
Make a representational reflexive coercion
mkNomReflCo :: Type -> Coercion Source #
Make a nominal reflexive coercion
mkCoVarCos :: [CoVar] -> [Coercion] Source #
mkAxInstCo :: Role -> CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Coercion Source #
mkUnbranchedAxInstCo :: Role -> CoAxiom Unbranched -> [Type] -> [Coercion] -> Coercion Source #
mkAxInstRHS :: CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Type Source #
mkUnbranchedAxInstRHS :: CoAxiom Unbranched -> [Type] -> [Coercion] -> Type Source #
mkAxInstLHS :: CoAxiom br -> BranchIndex -> [Type] -> [Coercion] -> Type Source #
Return the left-hand type of the axiom, when the axiom is instantiated at the types given.
mkUnbranchedAxInstLHS :: CoAxiom Unbranched -> [Type] -> [Coercion] -> Type Source #
Instantiate the left-hand side of an unbranched axiom
mkPiCo :: Role -> Var -> Coercion -> Coercion Source #
Make a forall Coercion
, where both types related by the coercion
are quantified over the same variable.
mkSymCo :: Coercion -> Coercion Source #
Create a symmetric version of the given Coercion
that asserts
equality between the same types but in the other "direction", so
a kind of t1 ~ t2
becomes the kind t2 ~ t1
.
:: Int | "n" |
-> CoercionN | multiplicity coercion |
-> Coercion | argument coercion |
-> Coercion | result coercion |
-> Coercion | nth coercion from a FunCo See Note [Function coercions] If FunCo _ mult arg_co res_co :: (s1:TYPE sk1 :mult-> s2:TYPE sk2) ~ (t1:TYPE tk1 :mult-> t2:TYPE tk2) Then we want to behave as if co was TyConAppCo mult argk_co resk_co arg_co res_co where argk_co :: sk1 ~ tk1 = mkNthCo 0 (mkKindCo arg_co) resk_co :: sk2 ~ tk2 = mkNthCo 0 (mkKindCo res_co) i.e. mkRuntimeRepCo |
Extract the nth field of a FunCo
nthCoRole :: Int -> Coercion -> Role Source #
If you're about to call mkNthCo r n co
, then r
should be
whatever nthCoRole n co
returns.
mkTyConAppCo :: HasDebugCallStack => Role -> TyCon -> [Coercion] -> Coercion Source #
Apply a type constructor to a list of coercions. It is the caller's responsibility to get the roles correct on argument coercions.
mkForAllCo :: TyCoVar -> CoercionN -> Coercion -> Coercion Source #
Make a Coercion from a tycovar, a kind coercion, and a body coercion. The kind of the tycovar should be the left-hand kind of the kind coercion. See Note [Unused coercion variable in ForAllCo]
mkHomoForAllCos :: [TyCoVar] -> Coercion -> Coercion Source #
Make a Coercion quantified over a type/coercion variable; the variable has the same type in both sides of the coercion
mkPhantomCo :: Coercion -> Type -> Type -> Coercion Source #
Make a phantom coercion between two types. The coercion passed in must be a nominal coercion between the kinds of the types.
mkHoleCo :: CoercionHole -> Coercion Source #
Make a coercion from a coercion hole
:: UnivCoProvenance | |
-> Role | role of the built coercion, "r" |
-> Type | t1 :: k1 |
-> Type | t2 :: k2 |
-> Coercion | :: t1 ~r t2 |
Make a universal coercion between two arbitrary types.
mkAxiomInstCo :: CoAxiom Branched -> BranchIndex -> [Coercion] -> Coercion Source #
:: Role | role of the created coercion, "r" |
-> Coercion | :: phi1 ~N phi2 |
-> Coercion | g1 :: phi1 |
-> Coercion | g2 :: phi2 |
-> Coercion | :: g1 ~r g2 |
Make a "coercion between coercions".
downgradeRole :: Role -> Role -> Coercion -> Coercion Source #
Like downgradeRole_maybe
, but panics if the change isn't a downgrade.
See Note [Role twiddling functions]
mkAxiomRuleCo :: CoAxiomRule -> [Coercion] -> Coercion Source #
mkGReflRightCo :: Role -> Type -> CoercionN -> Coercion Source #
Given ty :: k1
, co :: k1 ~ k2
,
produces co' :: ty ~r (ty |> co)
mkGReflLeftCo :: Role -> Type -> CoercionN -> Coercion Source #
Given ty :: k1
, co :: k1 ~ k2
,
produces co' :: (ty |> co) ~r ty
mkCoherenceLeftCo :: Role -> Type -> CoercionN -> Coercion -> Coercion Source #
Given ty :: k1
, co :: k1 ~ k2
, co2:: ty ~r ty'
,
produces @co' :: (ty |> co) ~r ty'
It is not only a utility function, but it saves allocation when co
is a GRefl coercion.
mkCoherenceRightCo :: Role -> Type -> CoercionN -> Coercion -> Coercion Source #
Given ty :: k1
, co :: k1 ~ k2
, co2:: ty' ~r ty
,
produces @co' :: ty' ~r (ty |> co)
It is not only a utility function, but it saves allocation when co
is a GRefl coercion.
castCoercionKind :: Coercion -> CoercionN -> CoercionN -> Coercion Source #
Creates a new coercion with both of its types casted by different casts
castCoercionKind g h1 h2
, where g :: t1 ~r t2
,
has type (t1 |> h1) ~r (t2 |> h2)
.
h1
and h2
must be nominal.
It calls coercionKindRole
, so it's quite inefficient (which I
stands for)
Use castCoercionKind2
instead if t1
, t2
, and r
are known beforehand.
castCoercionKind1 :: Coercion -> Role -> Type -> Type -> CoercionN -> Coercion Source #
castCoercionKind1 g r t1 t2 h
= coercionKind g r t1 t2 h h
That is, it's a specialised form of castCoercionKind, where the two
kind coercions are identical
castCoercionKind1 g r t1 t2 h
, where g :: t1 ~r t2
,
has type (t1 |> h) ~r (t2 |> h)
.
h
must be nominal.
See Note [castCoercionKind1]
castCoercionKind2 :: Coercion -> Role -> Type -> Type -> CoercionN -> CoercionN -> Coercion Source #
Creates a new coercion with both of its types casted by different casts
castCoercionKind2 g r t1 t2 h1 h2
, where g :: t1 ~r t2
,
has type (t1 |> h1) ~r (t2 |> h2)
.
h1
and h2
must be nominal.
mkFamilyTyConAppCo :: TyCon -> [CoercionN] -> CoercionN Source #
Given a family instance TyCon
and its arg Coercion
s, return the
corresponding family Coercion
. E.g:
data family T a data instance T (Maybe b) = MkT b
Where the instance TyCon
is :RTL, so:
mkFamilyTyConAppCo :RTL (co :: a ~# Int) = T (Maybe a) ~# T (Maybe Int)
cf. mkFamilyTyConApp
mkPrimEqPred :: Type -> Type -> Type Source #
Creates a primitive type equality predicate. Invariant: the types are not Coercions
mkPrimEqPredRole :: Role -> Type -> Type -> PredType Source #
Makes a lifted equality predicate at the given role
mkHeteroPrimEqPred :: Kind -> Kind -> Type -> Type -> Type Source #
Creates a primitive type equality predicate with explicit kinds
mkHeteroReprPrimEqPred :: Kind -> Kind -> Type -> Type -> Type Source #
Creates a primitive representational type equality predicate with explicit kinds
Decomposition
instNewTyCon_maybe :: TyCon -> [Type] -> Maybe (Type, Coercion) Source #
If co :: T ts ~ rep_ty
then:
instNewTyCon_maybe T ts = Just (rep_ty, co)
Checks for a newtype, and for being saturated
type NormaliseStepper ev = RecTcChecker -> TyCon -> [Type] -> NormaliseStepResult ev Source #
A function to check if we can reduce a type by one step. Used
with topNormaliseTypeX
.
data NormaliseStepResult ev Source #
The result of stepping in a normalisation function.
See topNormaliseTypeX
.
NS_Done | Nothing more to do |
NS_Abort | Utter failure. The outer function should fail too. |
NS_Step RecTcChecker Type ev | We stepped, yielding new bits; ^ ev is evidence; Usually a co :: old type ~ new type |
Instances
Outputable ev => Outputable (NormaliseStepResult ev) Source # | |
Defined in GHC.Core.Coercion ppr :: NormaliseStepResult ev -> SDoc Source # |
composeSteppers :: NormaliseStepper ev -> NormaliseStepper ev -> NormaliseStepper ev Source #
Try one stepper and then try the next, if the first doesn't make progress. So if it returns NS_Done, it means that both steppers are satisfied
mapStepResult :: (ev1 -> ev2) -> NormaliseStepResult ev1 -> NormaliseStepResult ev2 Source #
unwrapNewTypeStepper :: NormaliseStepper Coercion Source #
A NormaliseStepper
that unwraps newtypes, careful not to fall into
a loop. If it would fall into a loop, it produces NS_Abort
.
topNormaliseNewType_maybe :: Type -> Maybe (Coercion, Type) Source #
Sometimes we want to look through a newtype
and get its associated coercion.
This function strips off newtype
layers enough to reveal something that isn't
a newtype
. Specifically, here's the invariant:
topNormaliseNewType_maybe rec_nts ty = Just (co, ty')
then (a) co : ty ~ ty'
.
(b) ty' is not a newtype.
The function returns Nothing
for non-newtypes
,
or unsaturated applications
This function does *not* look through type families, because it has no access to the type family environment. If you do have that at hand, consider to use topNormaliseType_maybe, which should be a drop-in replacement for topNormaliseNewType_maybe If topNormliseNewType_maybe ty = Just (co, ty'), then co : ty ~R ty'
topNormaliseTypeX :: NormaliseStepper ev -> (ev -> ev -> ev) -> Type -> Maybe (ev, Type) Source #
A general function for normalising the top-level of a type. It continues
to use the provided NormaliseStepper
until that function fails, and then
this function returns. The roles of the coercions produced by the
NormaliseStepper
must all be the same, which is the role returned from
the call to topNormaliseTypeX
.
Typically ev is Coercion.
If topNormaliseTypeX step plus ty = Just (ev, ty')
then ty ~ev1~ t1 ~ev2~ t2 ... ~evn~ ty'
and ev = ev1 plus
ev2 plus
... plus
evn
If it returns Nothing then no newtype unwrapping could happen
decomposeFunCo :: HasDebugCallStack => Role -> Coercion -> (CoercionN, Coercion, Coercion) Source #
decomposePiCos :: HasDebugCallStack => CoercionN -> Pair Type -> [Type] -> ([CoercionN], CoercionN) Source #
getCoVar_maybe :: Coercion -> Maybe CoVar Source #
Attempts to obtain the type variable underlying a Coercion
splitTyConAppCo_maybe :: Coercion -> Maybe (TyCon, [Coercion]) Source #
Attempts to tease a coercion apart into a type constructor and the application of a number of coercion arguments to that constructor
splitAppCo_maybe :: Coercion -> Maybe (Coercion, Coercion) Source #
Attempt to take a coercion application apart.
splitForAllCo_ty_maybe :: Coercion -> Maybe (TyVar, Coercion, Coercion) Source #
Like splitForAllCo_maybe
, but only returns Just for tyvar binder
splitForAllCo_co_maybe :: Coercion -> Maybe (CoVar, Coercion, Coercion) Source #
Like splitForAllCo_maybe
, but only returns Just for covar binder
tyConRolesRepresentational :: TyCon -> [Role] Source #
setNominalRole_maybe :: Role -> Coercion -> Maybe Coercion Source #
Converts a coercion to be nominal, if possible. See Note [Role twiddling functions]
pickLR :: LeftOrRight -> (a, a) -> a Source #
isGReflCo :: Coercion -> Bool Source #
Tests if this coercion is obviously a generalized reflexive coercion. Guaranteed to work very quickly.
isReflCo :: Coercion -> Bool Source #
Tests if this coercion is obviously reflexive. Guaranteed to work
very quickly. Sometimes a coercion can be reflexive, but not obviously
so. c.f. isReflexiveCo
isReflCo_maybe :: Coercion -> Maybe (Type, Role) Source #
Returns the type coerced if this coercion is reflexive. Guaranteed
to work very quickly. Sometimes a coercion can be reflexive, but not
obviously so. c.f. isReflexiveCo_maybe
isGReflCo_maybe :: Coercion -> Maybe (Type, Role) Source #
Returns the type coerced if this coercion is a generalized reflexive coercion. Guaranteed to work very quickly.
isReflexiveCo :: Coercion -> Bool Source #
Slowly checks if the coercion is reflexive. Don't call this in a loop, as it walks over the entire coercion.
isReflexiveCo_maybe :: Coercion -> Maybe (Type, Role) Source #
Extracts the coerced type from a reflexive coercion. This potentially walks over the entire coercion, so avoid doing this in a loop.
isGReflMCo :: MCoercion -> Bool Source #
Tests if this MCoercion is obviously generalized reflexive Guaranteed to work very quickly.
mkGReflLeftMCo :: Role -> Type -> MCoercionN -> Coercion Source #
mkGReflRightMCo :: Role -> Type -> MCoercionN -> Coercion Source #
mkCoherenceRightMCo :: Role -> Type -> MCoercionN -> Coercion -> Coercion Source #
Like mkCoherenceRightCo
, but with an MCoercion
mkFunResMCo :: Scaled Type -> MCoercionR -> MCoercionR Source #
Coercion variables
isCoVar :: Var -> Bool Source #
Is this a coercion variable?
Satisfies
.isId
v ==> isCoVar
v == not (isNonCoVarId
v)
isCoVar_maybe :: Coercion -> Maybe CoVar Source #
Extract a covar, if possible. This check is dirty. Be ashamed of yourself. (It's dirty because it cares about the structure of a coercion, which is morally reprehensible.)
Free variables
tyCoVarsOfCo :: Coercion -> TyCoVarSet Source #
tyCoVarsOfCos :: [Coercion] -> TyCoVarSet Source #
coVarsOfCo :: Coercion -> CoVarSet Source #
tyCoFVsOfCo :: Coercion -> FV Source #
tyCoFVsOfCos :: [Coercion] -> FV Source #
tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet Source #
Get a deterministic set of the vars free in a coercion
coercionSize :: Coercion -> Int Source #
Substitution
substCo :: HasCallStack => TCvSubst -> Coercion -> Coercion Source #
Substitute within a Coercion
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCos :: HasCallStack => TCvSubst -> [Coercion] -> [Coercion] Source #
Substitute within several Coercion
s
The substitution has to satisfy the invariants described in
Note [The substitution invariant].
substCoWith :: HasCallStack => [TyVar] -> [Type] -> Coercion -> Coercion Source #
Coercion substitution, see zipTvSubst
substCoVarBndr :: HasCallStack => TCvSubst -> CoVar -> (TCvSubst, CoVar) Source #
getCvSubstEnv :: TCvSubst -> CvSubstEnv Source #
Lifting
liftCoSubst :: HasDebugCallStack => Role -> LiftingContext -> Type -> Coercion Source #
liftCoSubst role lc ty
produces a coercion (at role role
)
that coerces between lc_left(ty)
and lc_right(ty)
, where
lc_left
is a substitution mapping type variables to the left-hand
types of the mapped coercions in lc
, and similar for lc_right
.
liftCoSubstTyVar :: LiftingContext -> Role -> TyVar -> Maybe Coercion Source #
liftCoSubstWithEx :: Role -> [TyVar] -> [Coercion] -> [TyCoVar] -> [Type] -> (Type -> Coercion, [Type]) Source #
:: LiftingContext | original LC |
-> TyCoVar | new variable to map... |
-> Coercion | ...to this lifted version |
-> LiftingContext |
Extend a lifting context with a new mapping.
extendLiftingContextAndInScope Source #
:: LiftingContext | Original LC |
-> TyCoVar | new variable to map... |
-> Coercion | to this coercion |
-> LiftingContext |
Extend a lifting context with a new mapping, and extend the in-scope set
liftCoSubstVarBndrUsing :: (LiftingContext -> Type -> (CoercionN, a)) -> LiftingContext -> TyCoVar -> (LiftingContext, TyCoVar, CoercionN, a) Source #
isMappedByLC :: TyCoVar -> LiftingContext -> Bool Source #
Is a var in the domain of a lifting context?
zapLiftingContext :: LiftingContext -> LiftingContext Source #
Erase the environments in a lifting context
substForAllCoBndrUsingLC :: Bool -> (Coercion -> Coercion) -> LiftingContext -> TyCoVar -> Coercion -> (LiftingContext, TyCoVar, Coercion) Source #
Like substForAllCoBndr
, but works on a lifting context
lcTCvSubst :: LiftingContext -> TCvSubst Source #
Extract the underlying substitution from the LiftingContext
lcInScopeSet :: LiftingContext -> InScopeSet Source #
Get the InScopeSet
from a LiftingContext
data LiftingContext Source #
Instances
Outputable LiftingContext Source # | |
Defined in GHC.Core.Coercion ppr :: LiftingContext -> SDoc Source # |
substRightCo :: LiftingContext -> Coercion -> Coercion Source #
substLeftCo :: LiftingContext -> Coercion -> Coercion Source #
lcSubstLeft :: LiftingContext -> TCvSubst Source #
Comparison
eqCoercionX :: RnEnv2 -> Coercion -> Coercion -> Bool Source #
Compare two Coercion
s, with respect to an RnEnv2
Forcing evaluation of coercions
Pretty-printing
pprParendCo :: Coercion -> SDoc Source #
pprCoAxiom :: CoAxiom br -> SDoc Source #
pprCoAxBranch :: TyCon -> CoAxBranch -> SDoc Source #
pprCoAxBranchLHS :: TyCon -> CoAxBranch -> SDoc Source #
pprCoAxBranchUser :: TyCon -> CoAxBranch -> SDoc Source #
etaExpandCoAxBranch :: CoAxBranch -> ([TyVar], [Type], Type) Source #
Tidying
tidyCo :: TidyEnv -> Coercion -> Coercion Source #
Tidy a Coercion
See Note [Strictness in tidyType and friends]
Other
promoteCoercion :: Coercion -> CoercionN Source #
like mkKindCo, but aggressively & recursively optimizes to avoid using a KindCo constructor. The output role is nominal.
buildCoercion :: Type -> Type -> CoercionN Source #
Assuming that two types are the same, ignoring coercions, find a nominal coercion between the types. This is useful when optimizing transitivity over coercion applications, where splitting two AppCos might yield different kinds. See Note [EtaAppCo] in GHC.Core.Coercion.Opt.
simplifyArgsWorker :: [TyCoBinder] -> Kind -> TyCoVarSet -> [Role] -> [(Type, Coercion)] -> ([Type], [Coercion], MCoercionN) Source #
hasCoercionHoleTy :: Type -> Bool Source #
Is there a coercion hole in this type?
hasCoercionHoleCo :: Coercion -> Bool Source #
Is there a coercion hole in this coercion?
type HoleSet = UniqSet CoercionHole Source #
A set of CoercionHole
s
coercionHolesOfType :: Type -> UniqSet CoercionHole Source #
Extract out all the coercion holes from a given type