Agda-2.5.4: A dependently typed functional programming language and proof assistant

Safe HaskellNone
LanguageHaskell2010

Agda.TypeChecking.Free.Lazy

Contents

Description

Computing the free variables of a term lazily.

We implement a reduce (traversal into monoid) over internal syntax for a generic collection (monoid with singletons). This should allow a more efficient test for the presence of a particular variable.

Worst-case complexity does not change (i.e. the case when a variable does not occur), but best case-complexity does matter. For instance, see mkAbs: each time we construct a dependent function type, we check it is actually dependent.

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

Synopsis

Documentation

data FlexRig #

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 MetaSet

In arguments of metas. The set of metas is used by 'NonLinMatch' to generate the right blocking information.

WeaklyRigid

In arguments to variables and definitions.

Unguarded

In top position, or only under inductive record constructors.

StronglyRigid

Under at least one and only inductive constructors.

Instances
Eq FlexRig # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

(==) :: FlexRig -> FlexRig -> Bool #

(/=) :: FlexRig -> FlexRig -> Bool #

Ord FlexRig # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Show FlexRig # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

composeFlexRig :: FlexRig -> FlexRig -> FlexRig #

FlexRig composition. For accumulating the context of a variable.

Flexible is dominant. Once we are under a meta, we are flexible regardless what else comes.

WeaklyRigid is next in strength. Destroys strong rigidity.

StronglyRigid is still dominant over Unguarded.

Unguarded is the unit. It is the top (identity) context.

data VarOcc #

Occurrence of free variables is classified by several dimensions. Currently, we have FlexRig and Relevance.

Constructors

VarOcc 
Instances
Eq VarOcc # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

(==) :: VarOcc -> VarOcc -> Bool #

(/=) :: VarOcc -> VarOcc -> Bool #

Show VarOcc # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

LensRelevance VarOcc # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Singleton (Variable, VarOcc) VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

singleton :: (Variable, VarOcc) -> VarMap #

maxVarOcc :: VarOcc -> VarOcc -> VarOcc #

When we extract information about occurrence, we care most about about StronglyRigid Relevant occurrences.

composeVarOcc :: VarOcc -> VarOcc -> VarOcc #

First argument is the outer occurrence and second is the inner.

class (Semigroup a, Monoid a) => IsVarSet a where #

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

Minimal complete definition

withVarOcc

Methods

withVarOcc :: VarOcc -> a -> a #

Laws * Respects monoid operations: ``` withVarOcc o mempty == mempty withVarOcc o (x <> y) == withVarOcc o x <> withVarOcc o y ``` * Respects VarOcc composition ``` withVarOcc (composeVarOcc o1 o2) = withVarOcc o1 . withVarOcc o2 ```

Instances
IsVarSet All # 
Instance details

Defined in Agda.TypeChecking.Free

Methods

withVarOcc :: VarOcc -> All -> All #

IsVarSet Any # 
Instance details

Defined in Agda.TypeChecking.Free

Methods

withVarOcc :: VarOcc -> Any -> Any #

IsVarSet VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

withVarOcc :: VarOcc -> VarMap -> VarMap #

IsVarSet VarCounts # 
Instance details

Defined in Agda.TypeChecking.Free

IsVarSet FreeVars # 
Instance details

Defined in Agda.TypeChecking.Free

IsVarSet [Int] # 
Instance details

Defined in Agda.TypeChecking.Free

Methods

withVarOcc :: VarOcc -> [Int] -> [Int] #

newtype VarMap #

Constructors

VarMap 

Fields

Instances
Show VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Semigroup VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Monoid VarMap #

Proper monoid instance for VarMap rather than inheriting the broken one from IntMap. We combine two occurrences of a variable using maxVarOcc.

Instance details

Defined in Agda.TypeChecking.Free.Lazy

IsVarSet VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

withVarOcc :: VarOcc -> VarMap -> VarMap #

Singleton (Variable, VarOcc) VarMap # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

singleton :: (Variable, VarOcc) -> VarMap #

Collecting free variables.

data IgnoreSorts #

Where should we skip sorts in free variable analysis?

Constructors

IgnoreNot

Do not skip.

IgnoreInAnnotations

Skip when annotation to a type.

IgnoreAll

Skip unconditionally.

Instances
Eq IgnoreSorts # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Show IgnoreSorts # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

data FreeEnv c #

The current context.

Constructors

FreeEnv 

Fields

Instances
Semigroup c => Semigroup (FreeM c) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

(<>) :: FreeM c -> FreeM c -> FreeM c #

sconcat :: NonEmpty (FreeM c) -> FreeM c #

stimes :: Integral b => b -> FreeM c -> FreeM c #

(Semigroup c, Monoid c) => Monoid (FreeM c) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

mempty :: FreeM c #

mappend :: FreeM c -> FreeM c -> FreeM c #

mconcat :: [FreeM c] -> FreeM c #

type Variable = Int #

type SingleVar c = Variable -> c #

initFreeEnv :: Monoid c => SingleVar c -> FreeEnv c #

The initial context.

type FreeM c = Reader (FreeEnv c) c #

runFreeM :: IsVarSet c => SingleVar c -> IgnoreSorts -> FreeM c -> c #

Run function for FreeM.

variable :: IsVarSet c => Int -> FreeM c #

Base case: a variable.

subVar :: Int -> Maybe Variable -> Maybe Variable #

Subtract, but return Nothing if result is negative.

bind :: FreeM a -> FreeM a #

Going under a binder.

bind' :: Nat -> FreeM a -> FreeM a #

go :: FlexRig -> FreeM a -> FreeM a #

Changing the FlexRig context.

goRel :: Relevance -> FreeM a -> FreeM a #

Changing the Relevance.

underConstructor :: ConHead -> FreeM a -> FreeM a #

What happens to the variables occurring under a constructor?

class Free a where #

Gather free variables in a collection.

Minimal complete definition

freeVars'

Methods

freeVars' :: IsVarSet c => a -> FreeM c #

Instances
Free EqualityView # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => EqualityView -> FreeM c #

Free Clause # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Clause -> FreeM c #

Free LevelAtom # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => LevelAtom -> FreeM c #

Free PlusLevel # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => PlusLevel -> FreeM c #

Free Level # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Level -> FreeM c #

Free Sort # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Sort -> FreeM c #

Free Term # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Term -> FreeM c #

Free Candidate # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Methods

freeVars' :: IsVarSet c => Candidate -> FreeM c #

Free NLPType # 
Instance details

Defined in Agda.TypeChecking.Rewriting

Methods

freeVars' :: IsVarSet c => NLPType -> FreeM c #

Free NLPat # 
Instance details

Defined in Agda.TypeChecking.Rewriting

Methods

freeVars' :: IsVarSet c => NLPat -> FreeM c #

Free DisplayTerm # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Methods

freeVars' :: IsVarSet c => DisplayTerm -> FreeM c #

Free DisplayForm # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Methods

freeVars' :: IsVarSet c => DisplayForm -> FreeM c #

Free Constraint # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Methods

freeVars' :: IsVarSet c => Constraint -> FreeM c #

Free a => Free [a] # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => [a] -> FreeM c #

Free a => Free (Maybe a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Maybe a -> FreeM c #

Free a => Free (Dom a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Dom a -> FreeM c #

Free a => Free (Arg a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Arg a -> FreeM c #

Free a => Free (Tele a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Tele a -> FreeM c #

Free a => Free (Type' a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Type' a -> FreeM c #

Free a => Free (Abs a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Abs a -> FreeM c #

Free a => Free (Elim' a) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => Elim' a -> FreeM c #

(Free a, Free b) => Free (a, b) # 
Instance details

Defined in Agda.TypeChecking.Free.Lazy

Methods

freeVars' :: IsVarSet c => (a, b) -> FreeM c #