ModuleAgda-2.7.0.1Haskell2010
Agda.TypeChecking.Free
Computing the free variables of a term.
The distinction between rigid and strongly rigid occurrences comes from: Jason C. Reed, PhD thesis, 2009, page 96 (see also his LFMTP 2009 paper)
The main idea is that x = t(x) is unsolvable if x occurs strongly rigidly in t. It might have a solution if the occurrence is not strongly rigid, e.g.
x = f -> suc (f (x ( y -> k))) has x = f -> suc (f (suc k))
- Jason C. Reed, PhD thesis, page 106
Under coinductive constructors, occurrences are never strongly rigid. Also, function types and lambdas do not establish strong rigidity. Only inductive constructors do so. (See issue 1271).
If you need the occurrence information for all free variables, you can use
freeVars which has amoungst others this instance
freeVars :: Term -> VarMap
From VarMap, specific information can be extracted, e.g.,
relevantVars :: VarMap -> VarSet
relevantVars = filterVarMap isRelevant
To just check the status of a single free variable, there are more
efficient methods, e.g.,
freeIn :: Nat -> Term -> Bool
Tailored optimized variable checks can be implemented as semimodules to VarOcc,
see, for example, VarCounts or SingleFlexRig.
- 7 types
- 3 classes
- 28 values
- PackageAgda-2.7.0.1
- Exports39
- LanguageHaskell2010
- LicenceMIT
- SourceFree.hs
Gather free variables in a collection.
Instances27Free, …
Free ClauseDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree EqualityViewDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree LevelDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree SortDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree TermDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree CandidateDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.BaseFree CompareAsDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.BaseFree ConstraintDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.BaseFree DisplayFormDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.BaseFree DisplayTermDefined in Agda-2.7.0.1 · Agda.TypeChecking.Monad.BaseFree NLPSortDefined in Agda-2.7.0.1 · Agda.TypeChecking.Rewriting.NonLinPattern · orphanFree NLPTypeDefined in Agda-2.7.0.1 · Agda.TypeChecking.Rewriting.NonLinPattern · orphanFree NLPatDefined in Agda-2.7.0.1 · Agda.TypeChecking.Rewriting.NonLinPattern · orphanFree t => Free (Arg t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (WithHiding t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Abs t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Dom t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (PlusLevel' t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Tele t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Type' t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Elim' t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (SingleLevel' t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.LevelFree t => Free (Maybe t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free [t]Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFree t => Free (Named nm t)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy(Free t, Free u) => Free (t, u)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy(Free t, Free u, Free v) => Free (t, u, v)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy
class (Singleton MetaId a, Semigroup a, Monoid a, Semigroup c, Monoid c) => IsVarSet a c | c -> a whereAny representation c of a set of variables need to be able to be modified by
a variable occurrence. This is to ensure that free variable analysis is
compositional. For instance, it should be possible to compute `fv (v [u/x])`
from `fv v` and `fv u`.
In algebraic terminology, a variable set a needs to be (almost) a left semimodule
to the semiring VarOcc.
Methods
withVarOcc :: VarOcc' a -> c -> cLaws * Respects monoid operations: ``` withVarOcc o mempty == mempty withVarOcc o (x <> y) == withVarOcc o x <> withVarOcc o y ``` * Respects VarOcc composition: ``` withVarOcc oneVarOcc = id withVarOcc (composeVarOcc o1 o2) = withVarOcc o1 . withVarOcc o2 ``` * Respects VarOcc aggregation: ``` withVarOcc (o1 <> o2) x = withVarOcc o1 x <> withVarOcc o2 x ``` Since the corresponding unit law may fail, ``` withVarOcc mempty x = mempty ``` it is not quite a semimodule.
Instances11IsVarSet, …
IsVarSet MetaSet SingleFlexRigDefined in Agda-2.7.0.1 · Agda.TypeChecking.FreeIsVarSet MetaSet SingleVarOccDefined in Agda-2.7.0.1 · Agda.TypeChecking.FreeIsVarSet () VarCountsDefined in Agda-2.7.0.1 · Agda.TypeChecking.FreeIsVarSet () VarSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free · orphanIsVarSet () FlexRigMapDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyCompose everything with the varFlexRig part of the VarOcc.
IsVarSet () AllowedVarDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs · orphanIsVarSet () AllDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free · orphanIsVarSet () AnyDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free · orphanIsVarSet () [Int]Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free · orphanIsVarSet a c => IsVarSet a (RelevantIn c)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free(Singleton MetaId a, Semigroup a, Monoid a) => IsVarSet a (VarMap' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy
Where should we skip sorts in free variable analysis?
Constructors
IgnoreNotDo not skip.
IgnoreInAnnotationsSkip when annotation to a type.
IgnoreAllSkip unconditionally.
Instances2Eq, Show
Eq IgnoreSortsDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyShow IgnoreSortsDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy
Collect all free variables together with information about their occurrence.
Doesn't go inside solved metas, but collects the variables from a
metavariable application X ts as flexibleVars.
Compute free variables.
Rigid variables: either strongly rigid, unguarded, or weakly rigid.
Variables under only and at least one inductive constructor(s).
Variables at top or only under inductive record constructors λs and Πs. The purpose of recording these separately is that they can still become strongly rigid if put under a constructor whereas weakly rigid ones stay weakly rigid.
Variables occuring in arguments of metas. These are only potentially free, depending how the meta variable is instantiated. The set contains the id's of the meta variables that this variable is an argument to.
Collect all free variables.
Collect all relevant free variables, excluding the "unused" ones.
Collect all relevant free variables, possibly ignoring sorts.
Is the variable bound by the abstraction actually used?
Depending on the surrounding context of a variable, it's occurrence can be classified as flexible or rigid, with finer distinctions.
The constructors are listed in increasing order (wrt. information content).
Constructors
Flexible aIn arguments of metas. The set of metas is used by '
Agda.TypeChecking.Rewriting.NonLinMatch'to generate the right blocking information. The semantics is that the status of a variable occurrence may change if one of the metas in the set gets solved. We may say the occurrence is tainted by the meta variables in the set.WeaklyRigidIn arguments to variables and definitions.
UnguardedIn top position, or only under inductive record constructors (unit).
StronglyRigidUnder at least one and only inductive constructors.
Instances6Functor, Foldable, Eq, Show, LensFlexRig, Singleton
Functor FlexRig'Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyFoldable FlexRig'Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyEq a => Eq (FlexRig' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyShow a => Show (FlexRig' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyLensFlexRig (FlexRig' a) aDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazySingleton (Variable, FlexRig' ()) FlexRigMapDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy
Methods
lensFlexRig :: Lens' o (FlexRig' a)
Instances3LensFlexRig
LensFlexRig (FlexRig' a) aDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyLensFlexRig (VarOcc' a) aDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyAccess to varFlexRig in VarOcc.
LensFlexRig (FreeEnv' a b c) aDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.Lazy
Occurrence of free variables is classified by several dimensions. Currently, we have FlexRig and Modality.
Constructors
Instances8Eq, Show, Semigroup, Monoid, LensModality, LensQuantity, …
Eq a => Eq (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyEquality up to origin.
Show a => Show (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazySemigroup a => Semigroup (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyThe default way of aggregating free variable info from subterms is by adding the variable occurrences. For instance, if we have a pair
(t₁,t₂)then andt₁haso₁the occurrences of a variablexandt₂haso₂the occurrences of the same variable, then(t₁,t₂)hasmappend o₁ o₂occurrences of that variable.From counting Quantity, we extrapolate this to FlexRig and Relevance: we care most about about StronglyRigid Relevant occurrences. E.g., if
t₁has a StronglyRigid occurrence andt₂a Flexible occurrence, then(t₁,t₂)still has a StronglyRigid occurrence. Analogously,Relevantoccurrences count most, as we wish e.g. to forbid relevant occurrences of variables that are declared to be irrelevant.VarOcc forms a semiring, and this monoid is the addition of the semiring.
(Semigroup a, Monoid a) => Monoid (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyThe neutral element for variable occurrence aggregation is least serious occurrence: flexible, irrelevant. This is also the absorptive element for composeVarOcc, if we ignore the MetaSet in Flexible.
LensModality (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyLensQuantity (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyLensRelevance (VarOcc' a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyLensFlexRig (VarOcc' a) aDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyAccess to varFlexRig in VarOcc.
Get the full occurrence information of a free variable.
Get the full occurrence information of a free variable.
Is the term entirely closed (no free variables)?
A set of meta variables. Forms a monoid under union.
Instances8Eq, Show, Semigroup, Monoid, Null, Singleton, …
Eq MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyShow MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazySemigroup MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyMonoid MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyNull MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazySingleton MetaId MetaSetDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free.LazyIsVarSet MetaSet SingleFlexRigDefined in Agda-2.7.0.1 · Agda.TypeChecking.FreeIsVarSet MetaSet SingleVarOccDefined in Agda-2.7.0.1 · Agda.TypeChecking.Free