ghc-8.2.2: The GHC API

Safe Haskell | None
Language | Haskell2010

Coercion

Contents

- Main data type
  - Functions over coercions
  - Constructing coercions
  - Decomposition
  - Coercion variables
  - Free variables
  - Substitution
  - Lifting
  - Comparison
  - Forcing evaluation of coercions
- Pretty-printing
- Tidying
- Other

Description

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 UnivCoProvenance
- data CoercionHole
- data LeftOrRight
  - = CLeft
  - | CRight
- data Var
- type CoVar = Id
- type TyCoVar = Id
- data Role
  - = Nominal
  - | Representational
  - | Phantom
- ltRole :: Role -> Role -> Bool
- coVarTypes :: CoVar -> Pair Type
- coVarKind :: CoVar -> Type
- coVarKindsTypesRole :: CoVar -> (Kind, Kind, Type, Type, Role)
- coVarRole :: CoVar -> Role
- coercionType :: Coercion -> Type
- coercionKind :: Coercion -> Pair Type
- coercionKinds :: [Coercion] -> Pair [Type]
- mkCoercionType :: Role -> Type -> Type -> Type
- coercionRole :: Coercion -> Role
- coercionKindRole :: Coercion -> (Pair Type, Role)
- 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 -> Coercion -> Coercion
- mkSymCo :: Coercion -> Coercion
- mkTransCo :: Coercion -> Coercion -> Coercion
- mkTransAppCo :: Role -> Coercion -> Type -> Type -> Role -> Coercion -> Type -> Type -> Role -> Coercion
- mkNthCo :: Int -> Coercion -> Coercion
- mkNthCoRole :: Role -> Int -> Coercion -> Coercion
- mkLRCo :: LeftOrRight -> Coercion -> Coercion
- mkInstCo :: Coercion -> Coercion -> Coercion
- mkAppCo :: Coercion -> Coercion -> Coercion
- mkAppCos :: Coercion -> [Coercion] -> Coercion
- mkTyConAppCo :: HasDebugCallStack => Role -> TyCon -> [Coercion] -> Coercion
- mkFunCo :: Role -> Coercion -> Coercion -> Coercion
- mkFunCos :: Role -> [Coercion] -> Coercion -> Coercion
- mkForAllCo :: TyVar -> Coercion -> Coercion -> Coercion
- mkForAllCos :: [(TyVar, Coercion)] -> Coercion -> Coercion
- mkHomoForAllCos :: [TyVar] -> Coercion -> Coercion
- mkHomoForAllCos_NoRefl :: [TyVar] -> Coercion -> Coercion
- mkPhantomCo :: Coercion -> Type -> Type -> Coercion
- mkHomoPhantomCo :: Type -> Type -> Coercion
- toPhantomCo :: Coercion -> Coercion
- mkUnsafeCo :: Role -> Type -> Type -> Coercion
- mkHoleCo :: CoercionHole -> Role -> Type -> Type -> Coercion
- mkUnivCo :: UnivCoProvenance -> Role -> Type -> Type -> Coercion
- mkSubCo :: Coercion -> Coercion
- mkAxiomInstCo :: CoAxiom Branched -> BranchIndex -> [Coercion] -> Coercion
- mkProofIrrelCo :: Role -> Coercion -> Coercion -> Coercion -> Coercion
- downgradeRole :: Role -> Role -> Coercion -> Coercion
- maybeSubCo :: EqRel -> Coercion -> Coercion
- mkAxiomRuleCo :: CoAxiomRule -> [Coercion] -> Coercion
- mkCoherenceCo :: Coercion -> Coercion -> Coercion
- mkCoherenceRightCo :: Coercion -> Coercion -> Coercion
- mkCoherenceLeftCo :: Coercion -> Coercion -> Coercion
- mkKindCo :: Coercion -> Coercion
- castCoercionKind :: Coercion -> Coercion -> Coercion -> Coercion
- mkHeteroCoercionType :: Role -> 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 -> [Coercion]
- decomposeFunCo :: Coercion -> (Coercion, Coercion)
- 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 (TyVar, Coercion, Coercion)
- nthRole :: Role -> TyCon -> Int -> Role
- tyConRolesX :: Role -> TyCon -> [Role]
- tyConRolesRepresentational :: TyCon -> [Role]
- setNominalRole_maybe :: Coercion -> Maybe Coercion
- pickLR :: LeftOrRight -> (a, a) -> a
- isReflCo :: Coercion -> Bool
- isReflCo_maybe :: Coercion -> Maybe (Type, Role)
- isReflexiveCo :: Coercion -> Bool
- isReflexiveCo_maybe :: Coercion -> Maybe (Type, Role)
- isReflCoVar_maybe :: CoVar -> Maybe Coercion
- 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
- 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 :: TCvSubst -> CoVar -> (TCvSubst, CoVar)
- extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> TCvSubst
- getCvSubstEnv :: TCvSubst -> CvSubstEnv
- liftCoSubst :: Role -> LiftingContext -> Type -> Coercion
- liftCoSubstTyVar :: LiftingContext -> Role -> TyVar -> Maybe Coercion
- liftCoSubstWith :: Role -> [TyCoVar] -> [Coercion] -> Type -> Coercion
- liftCoSubstWithEx :: Role -> [TyVar] -> [Coercion] -> [TyVar] -> [Type] -> (Type -> Coercion, [Type])
- emptyLiftingContext :: InScopeSet -> LiftingContext
- extendLiftingContext :: LiftingContext -> TyVar -> Coercion -> LiftingContext
- liftCoSubstVarBndrCallback :: (LiftingContext -> Type -> (Coercion, a)) -> LiftingContext -> TyVar -> (LiftingContext, TyVar, Coercion, a)
- isMappedByLC :: TyCoVar -> LiftingContext -> Bool
- mkSubstLiftingContext :: TCvSubst -> LiftingContext
- zapLiftingContext :: LiftingContext -> LiftingContext
- substForAllCoBndrCallbackLC :: Bool -> (Coercion -> Coercion) -> LiftingContext -> TyVar -> Coercion -> (LiftingContext, TyVar, 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
- pprCoBndr :: Name -> Coercion -> SDoc
- pprCoAxiom :: CoAxiom br -> SDoc
- pprCoAxBranch :: CoAxiom br -> CoAxBranch -> SDoc
- pprCoAxBranchHdr :: CoAxiom br -> BranchIndex -> SDoc
- tidyCo :: TidyEnv -> Coercion -> Coercion
- tidyCos :: TidyEnv -> [Coercion] -> [Coercion]
- promoteCoercion :: Coercion -> Coercion

# Main data type

data Coercion #

A `Coercion` is concrete evidence of the equality/convertibility of two types.

Instances

Data Coercion # |

Methods

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 :: (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 # |
Methods ppr :: Coercion -> SDoc # pprPrec :: Rational -> Coercion -> SDoc #

type CoercionN = Coercion #

type CoercionR = Coercion #

type CoercionP = Coercion #

data UnivCoProvenance #

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 UnivCoProvenance # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UnivCoProvenance -> c UnivCoProvenance Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UnivCoProvenance Source #

toConstr :: UnivCoProvenance -> Constr Source #

dataTypeOf :: UnivCoProvenance -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c UnivCoProvenance) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UnivCoProvenance) Source #

gmapT :: (forall b. Data b => b -> b) -> UnivCoProvenance -> UnivCoProvenance Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UnivCoProvenance -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UnivCoProvenance -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> UnivCoProvenance -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> UnivCoProvenance -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> UnivCoProvenance -> m UnivCoProvenance Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UnivCoProvenance -> m UnivCoProvenance Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UnivCoProvenance -> m UnivCoProvenance Source #

Outputable UnivCoProvenance # |
Methods ppr :: UnivCoProvenance -> SDoc # pprPrec :: Rational -> UnivCoProvenance -> SDoc #

data CoercionHole #

A coercion to be filled in by the type-checker. See Note [Coercion holes]

Instances

Data CoercionHole # |

Methods

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 :: (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 #

Outputable CoercionHole # |
Methods ppr :: CoercionHole -> SDoc # pprPrec :: Rational -> CoercionHole -> SDoc #

data LeftOrRight #

Constructors

CLeft |
CRight |

Instances

Eq LeftOrRight # |
Methods (==) :: LeftOrRight -> LeftOrRight -> Bool # (/=) :: LeftOrRight -> LeftOrRight -> Bool #
Data LeftOrRight # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LeftOrRight -> c LeftOrRight Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LeftOrRight Source #

toConstr :: LeftOrRight -> Constr Source #

dataTypeOf :: LeftOrRight -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LeftOrRight) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LeftOrRight) Source #

gmapT :: (forall b. Data b => b -> b) -> LeftOrRight -> LeftOrRight Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LeftOrRight -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LeftOrRight -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> LeftOrRight -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> LeftOrRight -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> LeftOrRight -> m LeftOrRight Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LeftOrRight -> m LeftOrRight Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LeftOrRight -> m LeftOrRight Source #

Outputable LeftOrRight # |
Methods ppr :: LeftOrRight -> SDoc # pprPrec :: Rational -> LeftOrRight -> SDoc #
Binary LeftOrRight # |
Methods put_ :: BinHandle -> LeftOrRight -> IO () # put :: BinHandle -> LeftOrRight -> IO (Bin * LeftOrRight) # get :: BinHandle -> IO LeftOrRight #

data Var #

Variable

Essentially a typed `Name`, that may also contain some additional information about the `Var` and it's use sites.

Instances

Eq Var # |
Methods (==) :: Var -> Var -> Bool # (/=) :: Var -> Var -> Bool #
Data Var # |

Methods

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 :: (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 #

Ord Var # |
Methods compare :: Var -> Var -> Ordering # (<) :: Var -> Var -> Bool # (<=) :: Var -> Var -> Bool # (>) :: Var -> Var -> Bool # (>=) :: Var -> Var -> Bool # max :: Var -> Var -> Var # min :: Var -> Var -> Var #
Outputable Var # |
Methods ppr :: Var -> SDoc # pprPrec :: Rational -> Var -> SDoc #
Uniquable Var # |
Methods getUnique :: Var -> Unique #
HasOccName Var # |
Methods occName :: Var -> OccName #
NamedThing Var # |
Methods getOccName :: Var -> OccName # getName :: Var -> Name #
type PostRn Id ty # |
type PostRn Id ty = ty
type PostTc Id ty # |
type PostTc Id ty = ty

type CoVar = Id #

Coercion Variable

type TyCoVar = Id #

Type or Coercion Variable

data Role #

Constructors

Nominal |
Representational |
Phantom |

Instances

Eq Role # |
Methods (==) :: Role -> Role -> Bool # (/=) :: Role -> Role -> Bool #
Data Role # |

Methods

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 :: (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 #

Ord Role # |
Methods compare :: Role -> Role -> Ordering # (<) :: Role -> Role -> Bool # (<=) :: Role -> Role -> Bool # (>) :: Role -> Role -> Bool # (>=) :: Role -> Role -> Bool # max :: Role -> Role -> Role # min :: Role -> Role -> Role #
Outputable Role # |
Methods ppr :: Role -> SDoc # pprPrec :: Rational -> Role -> SDoc #
Binary Role # |
Methods put_ :: BinHandle -> Role -> IO () # put :: BinHandle -> Role -> IO (Bin * Role) # get :: BinHandle -> IO Role #

ltRole :: Role -> Role -> Bool #

## Functions over coercions

coVarTypes :: CoVar -> Pair Type #

coVarKind :: CoVar -> Type #

coVarKindsTypesRole :: CoVar -> (Kind, Kind, Type, Type, Role) #

coVarRole :: CoVar -> Role #

coercionType :: Coercion -> Type #

coercionKind :: Coercion -> Pair Type #

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`.

coercionKinds :: [Coercion] -> Pair [Type] #

Apply `coercionKind` to multiple `Coercion`s

mkCoercionType :: Role -> Type -> Type -> Type #

Makes a coercion type from two types: the types whose equality is proven by the relevant `Coercion`

coercionRole :: Coercion -> Role #

Retrieve the role from a coercion.

coercionKindRole :: Coercion -> (Pair Type, Role) #

Get a coercion's kind and role. Why both at once? See Note [Computing a coercion kind and role]

## Constructing coercions

mkReflCo :: Role -> Type -> Coercion #

mkRepReflCo :: Type -> Coercion #

Make a representational reflexive coercion

mkNomReflCo :: Type -> Coercion #

Make a nominal reflexive 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 #

Return the left-hand type of the axiom, when the axiom is instantiated at the types given.

mkUnbranchedAxInstLHS :: CoAxiom Unbranched -> [Type] -> [Coercion] -> Type #

Instantiate the left-hand side of an unbranched axiom

mkPiCo :: Role -> Var -> Coercion -> Coercion #

Make a forall `Coercion`, where both types related by the coercion are quantified over the same type variable.

mkPiCos :: Role -> [Var] -> Coercion -> Coercion #

mkCoCast :: Coercion -> Coercion -> Coercion #

mkSymCo :: Coercion -> Coercion #

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`.

mkTransCo :: Coercion -> Coercion -> Coercion #

Create a new `Coercion` by composing the two given `Coercion`s transitively. (co1 ; co2)

mkTransAppCo #

Arguments

:: Role | r1
-> Coercion | co1 :: ty1a ~r1 ty1b
-> Type | ty1a
-> Type | ty1b
-> Role | r2
-> Coercion | co2 :: ty2a ~r2 ty2b
-> Type | ty2a
-> Type | ty2b
-> Role | r3
-> Coercion | :: ty1a ty2a ~r3 ty1b ty2b

Like `mkAppCo`, but allows the second coercion to be other than nominal. See Note [mkTransAppCo]. Role r3 cannot be more stringent than either r1 or r2.

mkNthCo :: Int -> Coercion -> Coercion #

mkNthCoRole :: Role -> Int -> Coercion -> Coercion #

mkLRCo :: LeftOrRight -> Coercion -> Coercion #

mkInstCo :: Coercion -> Coercion -> Coercion #

Instantiates a `Coercion`.

mkAppCo #

Arguments

:: Coercion | :: t1 ~r t2
-> Coercion | :: s1 ~N s2, where s1 :: k1, s2 :: k2
-> Coercion | :: t1 s1 ~r t2 s2

Apply a `Coercion` to another `Coercion`. The second coercion must be Nominal, unless the first is Phantom. If the first is Phantom, then the second can be either Phantom or Nominal.

mkAppCos :: Coercion -> [Coercion] -> Coercion #

Applies multiple `Coercion`s to another `Coercion`, from left to right. See also `mkAppCo`.

mkTyConAppCo :: HasDebugCallStack => Role -> TyCon -> [Coercion] -> Coercion #

Apply a type constructor to a list of coercions. It is the caller's responsibility to get the roles correct on argument coercions.

mkFunCo :: Role -> Coercion -> Coercion -> Coercion #

Build a function `Coercion` from two other `Coercion`s. That is, given `co1 :: a ~ b` and `co2 :: x ~ y` produce `co :: (a -> x) ~ (b -> y)`.

mkFunCos :: Role -> [Coercion] -> Coercion -> Coercion #

Make nested function `Coercion`s

mkForAllCo :: TyVar -> Coercion -> Coercion -> Coercion #

Make a Coercion from a tyvar, a kind coercion, and a body coercion. The kind of the tyvar should be the left-hand kind of the kind coercion.

mkForAllCos :: [(TyVar, Coercion)] -> Coercion -> Coercion #

Make nested ForAllCos

mkHomoForAllCos :: [TyVar] -> Coercion -> Coercion #

Make a Coercion quantified over a type variable; the variable has the same type in both sides of the coercion

mkHomoForAllCos_NoRefl :: [TyVar] -> Coercion -> Coercion #

Like `mkHomoForAllCos`, but doesn't check if the inner coercion is reflexive.

mkPhantomCo :: Coercion -> Type -> Type -> Coercion #

Make a phantom coercion between two types. The coercion passed in must be a nominal coercion between the kinds of the types.

mkHomoPhantomCo :: Type -> Type -> Coercion #

Make a phantom coercion between two types of the same kind.

toPhantomCo :: Coercion -> Coercion #

mkUnsafeCo :: Role -> Type -> Type -> Coercion #

Manufacture an unsafe coercion from thin air. Currently (May 14) this is used only to implement the `unsafeCoerce#` primitive. Optimise by pushing down through type constructors.

mkHoleCo :: CoercionHole -> Role -> Type -> Type -> Coercion #

Make a coercion from a coercion hole

mkUnivCo #

Arguments

:: 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.

mkSubCo :: Coercion -> Coercion #

mkAxiomInstCo :: CoAxiom Branched -> BranchIndex -> [Coercion] -> Coercion #

mkProofIrrelCo #

Arguments

:: 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 #

Like `downgradeRole_maybe`, but panics if the change isn't a downgrade. See Note [Role twiddling functions]

maybeSubCo :: EqRel -> Coercion -> Coercion #

If the EqRel is ReprEq, makes a SubCo; otherwise, does nothing. Note that the input coercion should always be nominal.

mkAxiomRuleCo :: CoAxiomRule -> [Coercion] -> Coercion #

mkCoherenceCo :: Coercion -> Coercion -> Coercion infixl 5 #

mkCoherenceRightCo :: Coercion -> Coercion -> Coercion infixl 5 #

A CoherenceCo c1 c2 applies the coercion c2 to the left-hand type in the kind of c1. This function uses sym to get the coercion on the right-hand type of c1. Thus, if c1 :: s ~ t, then mkCoherenceRightCo c1 c2 has the kind (s ~ (t |> c2)) down through type constructors. The second coercion must be representational.

mkCoherenceLeftCo :: Coercion -> Coercion -> Coercion infixl 5 #

An explicitly directed synonym of mkCoherenceCo. The second coercion must be representational.

mkKindCo :: Coercion -> Coercion #

Given `co :: (a :: k) ~ (b :: k')` produce `co' :: k ~ k'`.

castCoercionKind :: Coercion -> Coercion -> Coercion -> Coercion #

Creates a new coercion with both of its types casted by different casts castCoercionKind g h1 h2, where g :: t1 ~ t2, has type (t1 |> h1) ~ (t2 |> h2) The second and third coercions must be nominal.

mkHeteroCoercionType :: Role -> Kind -> Kind -> Type -> Type -> Type #

## Decomposition

instNewTyCon_maybe :: TyCon -> [Type] -> Maybe (Type, Coercion) #

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 #

A function to check if we can reduce a type by one step. Used with `topNormaliseTypeX`.

data NormaliseStepResult ev #

The result of stepping in a normalisation function. See `topNormaliseTypeX`.

Constructors

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

composeSteppers :: NormaliseStepper ev -> NormaliseStepper ev -> NormaliseStepper ev #

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 #

unwrapNewTypeStepper :: NormaliseStepper Coercion #

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) #

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 : ty0 ~ 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) #

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

decomposeCo :: Arity -> Coercion -> [Coercion] #

This breaks a `Coercion` with type `T A B C ~ T D E F` into a list of `Coercion`s of kinds `A ~ D`, `B ~ E` and `E ~ F`. Hence:

    decomposeCo 3 c = [nth 0 c, nth 1 c, nth 2 c]

decomposeFunCo :: Coercion -> (Coercion, Coercion) #

getCoVar_maybe :: Coercion -> Maybe CoVar #

Attempts to obtain the type variable underlying a `Coercion`

splitTyConAppCo_maybe :: Coercion -> Maybe (TyCon, [Coercion]) #

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) #

Attempt to take a coercion application apart.

splitFunCo_maybe :: Coercion -> Maybe (Coercion, Coercion) #

splitForAllCo_maybe :: Coercion -> Maybe (TyVar, Coercion, Coercion) #

nthRole :: Role -> TyCon -> Int -> Role #

tyConRolesX :: Role -> TyCon -> [Role] #

tyConRolesRepresentational :: TyCon -> [Role] #

setNominalRole_maybe :: Coercion -> Maybe Coercion #

Converts a coercion to be nominal, if possible. See Note [Role twiddling functions]

pickLR :: LeftOrRight -> (a, a) -> a #

isReflCo :: Coercion -> Bool #

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) #

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`

isReflexiveCo :: Coercion -> Bool #

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) #

Extracts the coerced type from a reflexive coercion. This potentially walks over the entire coercion, so avoid doing this in a loop.

isReflCoVar_maybe :: CoVar -> Maybe Coercion #

## Coercion variables

mkCoVar :: Name -> Type -> CoVar #

isCoVar :: Var -> Bool #

coVarName :: CoVar -> Name #

setCoVarName :: CoVar -> Name -> CoVar #

setCoVarUnique :: CoVar -> Unique -> CoVar #

isCoVar_maybe :: Coercion -> Maybe CoVar #

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 #

tyCoVarsOfCos :: [Coercion] -> TyCoVarSet #

coVarsOfCo :: Coercion -> CoVarSet #

tyCoFVsOfCo :: Coercion -> FV #

tyCoFVsOfCos :: [Coercion] -> FV #

tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet #

Get a deterministic set of the vars free in a coercion

coercionSize :: Coercion -> Int #

## Substitution

type CvSubstEnv = CoVarEnv Coercion #

A substitution of `Coercion`s for `CoVar`s

emptyCvSubstEnv :: CvSubstEnv #

lookupCoVar :: TCvSubst -> Var -> Maybe Coercion #

substCo :: HasCallStack => TCvSubst -> Coercion -> Coercion #

Substitute within a `Coercion` The substitution has to satisfy the invariants described in Note [The substitution invariant].

substCos :: HasCallStack => TCvSubst -> [Coercion] -> [Coercion] #

Substitute within several `Coercion`s The substitution has to satisfy the invariants described in Note [The substitution invariant].

substCoVar :: TCvSubst -> CoVar -> Coercion #

substCoVars :: TCvSubst -> [CoVar] -> [Coercion] #

substCoWith :: HasCallStack => [TyVar] -> [Type] -> Coercion -> Coercion #

Coercion substitution, see `zipTvSubst`

substCoVarBndr :: TCvSubst -> CoVar -> (TCvSubst, CoVar) #

extendTvSubstAndInScope :: TCvSubst -> TyVar -> Type -> TCvSubst #

getCvSubstEnv :: TCvSubst -> CvSubstEnv #

## Lifting

liftCoSubst :: Role -> LiftingContext -> Type -> Coercion #

`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 #

liftCoSubstWith :: Role -> [TyCoVar] -> [Coercion] -> Type -> Coercion #

liftCoSubstWithEx :: Role -> [TyVar] -> [Coercion] -> [TyVar] -> [Type] -> (Type -> Coercion, [Type]) #

emptyLiftingContext :: InScopeSet -> LiftingContext #

extendLiftingContext #

Arguments

:: LiftingContext | original LC
-> TyVar | new variable to map...
-> Coercion | ...to this lifted version
-> LiftingContext |

Extend a lifting context with a new type mapping.

liftCoSubstVarBndrCallback :: (LiftingContext -> Type -> (Coercion, a)) -> LiftingContext -> TyVar -> (LiftingContext, TyVar, Coercion, a) #

isMappedByLC :: TyCoVar -> LiftingContext -> Bool #

Is a var in the domain of a lifting context?

mkSubstLiftingContext :: TCvSubst -> LiftingContext #

zapLiftingContext :: LiftingContext -> LiftingContext #

Erase the environments in a lifting context

substForAllCoBndrCallbackLC :: Bool -> (Coercion -> Coercion) -> LiftingContext -> TyVar -> Coercion -> (LiftingContext, TyVar, Coercion) #

Like `substForAllCoBndr`, but works on a lifting context

lcTCvSubst :: LiftingContext -> TCvSubst #

Extract the underlying substitution from the LiftingContext

lcInScopeSet :: LiftingContext -> InScopeSet #

Get the `InScopeSet` from a `LiftingContext`

type LiftCoEnv = VarEnv Coercion #

data LiftingContext #

Constructors

LC TCvSubst LiftCoEnv |

Instances

Outputable LiftingContext # |
Methods ppr :: LiftingContext -> SDoc # pprPrec :: Rational -> LiftingContext -> SDoc #

liftEnvSubstLeft :: TCvSubst -> LiftCoEnv -> TCvSubst #

liftEnvSubstRight :: TCvSubst -> LiftCoEnv -> TCvSubst #

substRightCo :: LiftingContext -> Coercion -> Coercion #

substLeftCo :: LiftingContext -> Coercion -> Coercion #

swapLiftCoEnv :: LiftCoEnv -> LiftCoEnv #

Apply "sym" to all coercions in a `LiftCoEnv`

lcSubstLeft :: LiftingContext -> TCvSubst #

lcSubstRight :: LiftingContext -> TCvSubst #

## Comparison

eqCoercion :: Coercion -> Coercion -> Bool #

Syntactic equality of coercions

eqCoercionX :: RnEnv2 -> Coercion -> Coercion -> Bool #

Compare two `Coercion`s, with respect to an RnEnv2

## Forcing evaluation of coercions

seqCo :: Coercion -> () #

# Pretty-printing

pprCo :: Coercion -> SDoc #

pprParendCo :: Coercion -> SDoc #

pprCoBndr :: Name -> Coercion -> SDoc #

pprCoAxiom :: CoAxiom br -> SDoc #

pprCoAxBranch :: CoAxiom br -> CoAxBranch -> SDoc #

pprCoAxBranchHdr :: CoAxiom br -> BranchIndex -> SDoc #

# Tidying

tidyCo :: TidyEnv -> Coercion -> Coercion #

tidyCos :: TidyEnv -> [Coercion] -> [Coercion] #

# Other

promoteCoercion :: Coercion -> Coercion #

like mkKindCo, but aggressively & recursively optimizes to avoid using a KindCo constructor. The output role is nominal.