| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Mikan.TypeChecking.Telescope
Contents
Synopsis
- flattenTel :: TermSubst a => Tele (Dom a) -> [Dom a]
- flattenRevTel :: TermSubst a => Tele (Dom a) -> [Dom a]
- flattenContext :: Context -> [ContextEntry]
- reorderTel :: [Dom Type] -> Maybe Permutation
- reorderTel_ :: [Dom Type] -> Permutation
- unflattenTel :: [ArgName] -> [Dom Type] -> Telescope
- unflattenTel' :: Int -> [ArgName] -> [Dom Type] -> Telescope
- renameTel :: [Maybe ArgName] -> Telescope -> Telescope
- teleNames :: Telescope -> [ArgName]
- teleArgNames :: Telescope -> [Arg ArgName]
- teleArgs :: DeBruijn a => Tele (Dom t) -> [Arg a]
- teleDoms :: DeBruijn a => Tele (Dom t) -> [Dom a]
- teleNamedArgs :: DeBruijn a => Tele (Dom t) -> [NamedArg a]
- tele2NamedArgs :: DeBruijn a => Telescope -> Telescope -> [NamedArg a]
- splitTelescopeAt :: Int -> Telescope -> (Telescope, Telescope)
- takeTelescope :: Int -> Telescope -> Telescope
- dropEndTelescope :: Int -> Telescope -> Telescope
- permuteTel :: Permutation -> Telescope -> Telescope
- permuteContext :: Permutation -> Context -> Telescope
- varDependencies :: Telescope -> VarSet -> VarSet
- varDependents :: Telescope -> VarSet -> VarSet
- data SplitTel = SplitTel {}
- splitTelescope :: VarSet -> Int -> Telescope -> SplitTel
- splitTelescopeExact :: [Int] -> Telescope -> Maybe SplitTel
- instantiateTelescope :: Telescope -> Int -> DeBruijnPattern -> Maybe (Telescope, PatternSubstitution, Permutation)
- expandTelescopeVar :: Telescope -> Int -> Telescope -> ConHead -> (Telescope, PatternSubstitution)
- telView :: (MonadReduce m, MonadAddContext m) => Type -> m TelView
- telViewUpTo :: (MonadReduce m, MonadAddContext m) => Int -> Type -> m TelView
- telViewUpTo' :: (MonadReduce m, MonadAddContext m) => Int -> (Dom Type -> Bool) -> Type -> m TelView
- telViewPath :: PureTCM m => Type -> m TelView
- telViewUpToPath :: PureTCM m => Int -> Type -> m TelView
- newtype Boundary' x a = Boundary {
- theBoundary :: [(x, (a, a))]
- type Boundary = Boundary' Int Term
- type TmBoundary = Boundary' Term Term
- tmBoundary :: Boundary' Int a -> Boundary' Term a
- varBoundary :: Boundary' Term a -> Boundary' Int a
- telViewUpToPathBoundary' :: PureTCM m => Int -> Type -> m (TelView, Boundary)
- fullBoundary :: Telescope -> Boundary -> Boundary
- telViewUpToPathBoundary :: PureTCM m => Int -> Type -> m (TelView, Boundary)
- telViewPathBoundary :: PureTCM m => Type -> m (TelView, Boundary)
- teleElims :: DeBruijn a => Telescope -> Boundary' Int a -> [Elim' a]
- pathViewAsPi :: PureTCM m => Type -> m (Either (Dom Type, Abs Type) Type)
- pathViewAsPi' :: PureTCM m => Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type)
- pathViewAsPi'whnf :: HasBuiltins m => m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type)
- piOrPath :: HasBuiltins m => Type -> m (Either (Dom Type, Abs Type) Type)
- telView'UpToPath :: Int -> Type -> TCM TelView
- telView'Path :: Type -> TCM TelView
- isPath :: PureTCM m => Type -> m (Maybe (Dom Type, Abs Type))
- ifPath :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
- ifPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
- ifNotPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
- ifPiOrPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
- ifNotPiOrPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
- telePatterns :: DeBruijn a => Telescope -> Boundary -> [NamedArg (Pattern' a)]
- telePatterns' :: DeBruijn a => (forall a1. DeBruijn a1 => Telescope -> [NamedArg a1]) -> Telescope -> Boundary -> [NamedArg (Pattern' a)]
- mustBePi :: MonadReduce m => Type -> m (Dom Type, Abs Type)
- ifPi :: MonadReduce m => Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a
- ifPiB :: MonadReduce m => Term -> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a
- ifPiTypeB :: MonadReduce m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a
- ifPiType :: MonadReduce m => Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a
- ifNotPi :: MonadReduce m => Term -> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
- ifNotPiType :: MonadReduce m => Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
- ifNotPiOrPathType :: (MonadReduce tcm, HasBuiltins tcm) => Type -> (Type -> tcm a) -> (Dom Type -> Abs Type -> tcm a) -> tcm a
- shouldBePath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type)
- shouldBePi :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type)
- shouldBePiOrPath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type, Boundary)
- piApplyM'' :: (MonadReduce m, HasBuiltins m) => m Empty -> Type -> [Term] -> m Type
- class PiApplyArgs a where
- piApplyM' :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => m Empty -> Type -> a -> m Type
- piApplyM :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => Type -> a -> m Type
- typeArity :: Type -> TCM Nat
- foldrTelescopeM :: MonadAddContext m => (Dom (ArgName, Type) -> m b -> m b) -> m b -> Telescope -> m b
- teleApply' :: Teletype -> Args -> (Telescope -> Type -> a) -> (Type -> Args -> a) -> a
- teleApplyM :: (HasBuiltins m, MonadReduce m) => m Empty -> Teletype -> Args -> m Type
- teleApply :: HasCallStack => Teletype -> Args -> Type
- teleView :: MonadReduce m => Teletype -> m TelView
- teleType :: Telescope -> Type -> Teletype
- teleCons :: Dom (ArgName, Type) -> Teletype -> Teletype
- teleViewUpToPathBoundary :: PureTCM m => Int -> Teletype -> m (TelView, Boundary)
- teleViewUpToPath :: PureTCM m => Int -> Teletype -> m TelView
Documentation
flattenTel :: TermSubst a => Tele (Dom a) -> [Dom a] Source #
Flatten telescope: (Γ : Tel) -> [Type Γ].
flattenTel is lazy in both the spine and values of
the resulting list.
flattenRevTel :: TermSubst a => Tele (Dom a) -> [Dom a] Source #
Flatten telescope: (Γ : Tel) -> [Type Γ] into a reversed list.
flattenRevTel is lazy in both the spine and values of
the resulting list.
flattenContext :: Context -> [ContextEntry] Source #
Turn a context into a flat telescope: all entries live in the whole context.
(Γ : Context) -> [Type Γ]
reorderTel :: [Dom Type] -> Maybe Permutation Source #
Order a flattened telescope in the correct dependency order: Γ -> Permutation (Γ -> Γ~)
Since reorderTel tel uses free variable analysis of type in tel,
the telescope should be normalised.
reorderTel_ :: [Dom Type] -> Permutation Source #
unflattenTel :: [ArgName] -> [Dom Type] -> Telescope Source #
Unflatten: turns a flattened telescope into a proper telescope. Must be properly ordered.
unflattenTel' :: Int -> [ArgName] -> [Dom Type] -> Telescope Source #
A variant of unflattenTel which takes the size of the last
argument as an argument.
renameTel :: [Maybe ArgName] -> Telescope -> Telescope Source #
Rename the variables in the telescope to the given names
Precondition: size xs == size tel.
teleArgs :: DeBruijn a => Tele (Dom t) -> [Arg a] Source #
Convert a telescope to a list of Arg in left-to-right order:
teleArgs ((a : A) (b : B a) {c : C}) = [a, b, {c}] = [2, 1, {0}]teleDoms :: DeBruijn a => Tele (Dom t) -> [Dom a] Source #
Convert a telescope to a list of Dom in left-to-right order:
teleDoms ((a : A) (b : B a) {c : C}) = [a, b, {c}] = [2, 1, {0}]tele2NamedArgs :: DeBruijn a => Telescope -> Telescope -> [NamedArg a] Source #
A variant of teleNamedArgs which takes the argument names (and the argument info)
from the first telescope and the variable names from the second telescope.
Precondition: the two telescopes have the same length.
splitTelescopeAt :: Int -> Telescope -> (Telescope, Telescope) Source #
Split the telescope at the specified position.
takeTelescope :: Int -> Telescope -> Telescope Source #
Take the first n elements off of a telescope.
dropEndTelescope :: Int -> Telescope -> Telescope Source #
Drop the last n elements off of a telescope.
This is strict in the spine of the telescope.
permuteTel :: Permutation -> Telescope -> Telescope Source #
Permute telescope: permutes or drops the types in the telescope according to the given permutation (on de Bruijn _levels_). Assumes that the permutation preserves the dependencies in the telescope.
For example (Andreas, 2016-12-18, issue #2344):
tel = (A : Type) (X : _18 A) (i : Fin (_m_23 A X))
tel (de Bruijn) = 2:Type, 1:_18 0, 0:Fin(_m_23 1 0)
flattenTel tel = 2:Type, 1:_18 0, 0:Fin(_m_23 1 0) |- [ Type, _18 2, Fin (_m_23 2 1) ]
perm = 0,1,2 -> 0,1 (picks the first two)
renaming _ perm = [var 0, var 1, error] -- THE WRONG RENAMING! (levels)
renaming _ (reverseP perm) = [error, var 0, var 1] -- The correct renaming! (indices)
apply to flattened tel = ... |- [ Type, _18 1, Fin (_m_23 1 0) ]
permute perm it = ... |- [ Type, _18 1 ]
unflatten (de Bruijn) = 1:Type, 0: _18 0
unflatten = (A : Type) (X : _18 A)
permuteContext :: Permutation -> Context -> Telescope Source #
Like permuteTel, but start with a context.
varDependencies :: Telescope -> VarSet -> VarSet Source #
Recursively computes dependencies of a set of variables in a given telescope. Any dependencies outside of the telescope are ignored.
Note that varDependencies considers a variable to depend on itself.
varDependents :: Telescope -> VarSet -> VarSet Source #
Computes the set of variables in a telescope whose type depend on one of the variables in the given set (including recursive dependencies). Any dependencies outside of the telescope are ignored.
Unlike varDependencies, a variable is *not* considered to depend on itself.
A telescope split in two.
Constructors
| SplitTel | |
Fields
| |
Arguments
| :: VarSet | A set of de Bruijn indices. |
| -> Int | The first |
| -> Telescope | Original telescope. |
| -> SplitTel |
|
Split a telescope into the part that defines the given variables and the part that doesn't.
See prop_splitTelescope.
Arguments
| :: [Int] | A list of de Bruijn indices |
| -> Telescope | The telescope to split |
| -> Maybe SplitTel |
|
As splitTelescope, but fails if any additional variables or reordering would be needed to make the first part well-typed.
Arguments
| :: Telescope | ⊢ Γ |
| -> Int | Γ ⊢ var k : A de Bruijn _level_ |
| -> DeBruijnPattern | Γ ⊢ u : A |
| -> Maybe (Telescope, PatternSubstitution, Permutation) |
Try to instantiate one variable in the telescope (given by its de Bruijn level) with the given value, returning the new telescope and a substitution to the old one. Returns Nothing if the given value depends (directly or indirectly) on the variable.
expandTelescopeVar :: Telescope -> Int -> Telescope -> ConHead -> (Telescope, PatternSubstitution) Source #
Try to eta-expand one variable in the telescope (given by its de Bruijn level)
telView :: (MonadReduce m, MonadAddContext m) => Type -> m TelView Source #
Gather leading Πs of a type in a telescope.
telViewUpTo :: (MonadReduce m, MonadAddContext m) => Int -> Type -> m TelView Source #
telViewUpTo n t takes off the first n function types of t.
Takes off all if n < 0.
telViewUpTo' :: (MonadReduce m, MonadAddContext m) => Int -> (Dom Type -> Bool) -> Type -> m TelView Source #
telViewUpTo' n p t takes off $t$
the first n (or arbitrary many if n < 0) function domains
as long as they satify p.
telViewUpToPath :: PureTCM m => Int -> Type -> m TelView Source #
telViewUpToPath n t takes off t
the first n (or arbitrary many if n < 0) function domains or Path types.
telViewUpToPath n t = fst $ telViewUpToPathBoundary' n t
newtype Boundary' x a Source #
Boundary conditions [[ (i,(x,y)) ]] = [(i=0) -> x, (i=1) -> y].
For instance, if p : Path A a b, then p i has boundary condition (i,(a,b)).
We call i the dimension and (x,y) its boundary.
Constructors
| Boundary | |
Fields
| |
Instances
| Subst Boundary Source # | Substitution into a | ||||
Defined in Mikan.TypeChecking.Telescope Associated Types
Methods applySubst :: Substitution' (SubstArg Boundary) -> Boundary -> Boundary Source # | |||||
| Subst TmBoundary Source # | |||||
Defined in Mikan.TypeChecking.Telescope Associated Types
Methods applySubst :: Substitution' (SubstArg TmBoundary) -> TmBoundary -> TmBoundary Source # | |||||
| (Pretty x, Pretty a) => Pretty (Boundary' x a) Source # | |||||
| (PrettyTCM x, PrettyTCM a) => PrettyTCM (Boundary' x a) Source # | |||||
Defined in Mikan.TypeChecking.Pretty | |||||
| Null (Boundary' x a) Source # | |||||
| (Show x, Show a) => Show (Boundary' x a) Source # | |||||
| type SubstArg Boundary Source # | |||||
Defined in Mikan.TypeChecking.Telescope | |||||
| type SubstArg TmBoundary Source # | |||||
Defined in Mikan.TypeChecking.Telescope | |||||
type Boundary = Boundary' Int Term Source #
Usually, the dimensions of a boundary condition are interval variables,
represented by a de Bruijn index Int.
type TmBoundary = Boundary' Term Term Source #
Substitution formally creates dimensions that are interval expressions,
represented by a Term.
However, in practice these terms should be of the form .var i
tmBoundary :: Boundary' Int a -> Boundary' Term a Source #
Turn dimension variables i into dimension expressions .var i
varBoundary :: Boundary' Term a -> Boundary' Int a Source #
Turn dimension expressions into dimension variables. Formally this is a partial operation, but should only be called when the precondition is met.
Precondition: the dimension terms in the boundary are all of the form .var i
telViewUpToPathBoundary' :: PureTCM m => Int -> Type -> m (TelView, Boundary) Source #
Like telViewUpToPath but also returns the Boundary expected by the Path types encountered.
The boundary terms live in the telescope given by the TelView.
Each point of the boundary has the type of the codomain of the Path type it got taken from, see fullBoundary.
(TelV Γ b, [(i,t_i,u_i)]) <- telViewUpToPathBoundary' n a
Input: Δ ⊢ a
Output: Δ.Γ ⊢ b
Δ.Γ ⊢ T is the codomain of the PathP at variable i
Δ.Γ ⊢ i : I
Δ.Γ ⊢ [ (i=0) -> t_i; (i=1) -> u_i ] : T
Useful to reconstruct IApplyP patterns after teleNamedArgs Γ.
telViewUpToPathBoundary :: PureTCM m => Int -> Type -> m (TelView, Boundary) Source #
(TelV Γ b, [(i,t_i,u_i)]) <- telViewUpToPathBoundary n a
Input: Δ ⊢ a
Output: ΔΓ ⊢ b
ΔΓ ⊢ i : I
ΔΓ ⊢ [ (i=0) -> t_i; (i=1) -> u_i ] : b
teleElims :: DeBruijn a => Telescope -> Boundary' Int a -> [Elim' a] Source #
teleElimsB args bs = es
Input: Δ.Γ ⊢ args : Γ
Δ.Γ ⊢ T is the codomain of the PathP at variable i
Δ.Γ ⊢ i : I
Δ.Γ ⊢ bs = [ (i=0) -> t_i; (i=1) -> u_i ] : T
Output: Δ.Γ | PiPath Γ bs A ⊢ es : A
pathViewAsPi' :: PureTCM m => Type -> m (Either ((Dom Type, Abs Type), (Term, Term)) Type) Source #
Reduces Type.
pathViewAsPi'whnf :: HasBuiltins m => m (Type -> Either ((Dom Type, Abs Type), (Term, Term)) Type) Source #
piOrPath :: HasBuiltins m => Type -> m (Either (Dom Type, Abs Type) Type) Source #
Returns Left (a,b) in case the type is Pi a b or PathP b _ _.
Assumes the Type is in whnf.
ifPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a Source #
ifNotPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a Source #
ifPiOrPathB :: PureTCM m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a Source #
ifNotPiOrPathB :: PureTCM m => Type -> (Blocked Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a Source #
telePatterns' :: DeBruijn a => (forall a1. DeBruijn a1 => Telescope -> [NamedArg a1]) -> Telescope -> Boundary -> [NamedArg (Pattern' a)] Source #
ifPi :: MonadReduce m => Term -> (Dom Type -> Abs Type -> m a) -> (Term -> m a) -> m a Source #
If the given type is a Pi, pass its parts to the first continuation.
If not (or blocked), pass the reduced type to the second continuation.
ifPiB :: MonadReduce m => Term -> (Dom Type -> Abs Type -> m a) -> (Blocked Term -> m a) -> m a Source #
ifPiTypeB :: MonadReduce m => Type -> (Dom Type -> Abs Type -> m a) -> (Blocked Type -> m a) -> m a Source #
ifPiType :: MonadReduce m => Type -> (Dom Type -> Abs Type -> m a) -> (Type -> m a) -> m a Source #
If the given type is a Pi, pass its parts to the first continuation.
If not (or blocked), pass the reduced type to the second continuation.
ifNotPi :: MonadReduce m => Term -> (Term -> m a) -> (Dom Type -> Abs Type -> m a) -> m a Source #
If the given type is blocked or not a Pi, pass it reduced to the first continuation.
If it is a Pi, pass its parts to the second continuation.
ifNotPiType :: MonadReduce m => Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a Source #
If the given type is blocked or not a Pi, pass it reduced to the first continuation.
If it is a Pi, pass its parts to the second continuation.
ifNotPiOrPathType :: (MonadReduce tcm, HasBuiltins tcm) => Type -> (Type -> tcm a) -> (Dom Type -> Abs Type -> tcm a) -> tcm a Source #
shouldBePath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type) Source #
shouldBePi :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type) Source #
shouldBePiOrPath :: (PureTCM m, MonadBlock m, MonadTCError m) => Type -> m (Dom Type, Abs Type, Boundary) Source #
Arguments
| :: (MonadReduce m, HasBuiltins m) | |
| => m Empty | How to proceed if the type cannot be reduced to a |
| -> Type | The type to instantiate |
| -> [Term] | The arguments |
| -> m Type |
class PiApplyArgs a where Source #
Instances
| PiApplyArgs Term Source # | |
| PiApplyArgs a => PiApplyArgs (Arg a) Source # | |
| PiApplyArgs a => PiApplyArgs [a] Source # | |
Defined in Mikan.TypeChecking.Telescope | |
| PiApplyArgs a => PiApplyArgs (Named n a) Source # | |
piApplyM' :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => m Empty -> Type -> a -> m Type Source #
A version of piApplyM'' generalised over the arguments to
instantiate with.
piApplyM :: (MonadReduce m, HasBuiltins m, PiApplyArgs a) => Type -> a -> m Type Source #
A version of piApplyM'' generalised over the arguments to
instantiate with, throwing an error if there are
leftover arguments and the type can not be reduced to a __IMPOSSIBLE__Pi type.
foldrTelescopeM :: MonadAddContext m => (Dom (ArgName, Type) -> m b -> m b) -> m b -> Telescope -> m b Source #
Fold a telescope into a monadic computation, adding variables to the context at each step.
Teletypes
Arguments
| :: Teletype | The teletype to instantiate. |
| -> Args | The arguments. |
| -> (Telescope -> Type -> a) | How to handle running out of arguments. |
| -> (Type -> Args -> a) | How to handle running out of quantifiers. |
| -> a |
Instantiate a Teletype with some Args, attempting to produce a
Type.
Takes continuations for whether we ran out of arguments with leftover
quantification, or out of quantifiers with leftover arguments. Note
that, unlike teleView, the Type given to the "out of arguments"
continuation may include leading Pis.
Arguments
| :: (HasBuiltins m, MonadReduce m) | |
| => m Empty | How to error if there are leftover arguments and the "core" of the teletype does not compute to a function type. |
| -> Teletype | The teletype to instantiate. |
| -> Args | The arguments. |
| -> m Type |
teleApply :: HasCallStack => Teletype -> Args -> Type Source #
Instantiate a Teletype with some Args.
Leftover quantifiers are turned into dependent binders (),
as per Abs.telePi_
INVARIANT: the length of the arguments must not exceed the
explicit quantification in the teletype. If this is not known, use
the monadic teleApplyM instead.
teleCons :: Dom (ArgName, Type) -> Teletype -> Teletype Source #
Add a binding to the front of a Teletype.
teleViewUpToPathBoundary :: PureTCM m => Int -> Teletype -> m (TelView, Boundary) Source #
View a Teletype as a TelView, continuing into the "core" type
if necessary, returning the expected boundaries of any path
encountered along the way; a Teletype version of
telViewUpToPathBoundary.
The Int parameter, n, controls the number of quantifiers that may be
returned in the TelView. This means that if n is less than the
size of the teletype, any quantifiers will be moved into the type
part of the TelView.
This function is lazy in the Boundary, so it can be used even if
computing the boundary is not necessary.