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

Safe Haskell | None
Language | Haskell2010

Agda.TypeChecking.Free

Description

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

Synopsis

- data FreeVars = FV {
  - stronglyRigidVars :: VarSet
  - unguardedVars :: VarSet
  - weaklyRigidVars :: VarSet
  - flexibleVars :: IntMap MetaSet
  - irrelevantVars :: VarSet
  - unusedVars :: VarSet
  }
- type Free a = Free' a Any
- class Free' a c where
- type FreeV a = Free' a FreeVars
- type FreeVS a = Free' a VarSet
- data IgnoreSorts
  - = IgnoreNot
  - | IgnoreInAnnotations
  - | IgnoreAll
- runFree :: (Monoid c, Free' a c) => SingleVar c -> IgnoreSorts -> a -> c
- rigidVars :: FreeVars -> VarSet
- relevantVars :: FreeVars -> VarSet
- allVars :: FreeVars -> VarSet
- allFreeVars :: Free' a VarSet => a -> VarSet
- allRelevantVars :: Free' a VarSet => a -> VarSet
- allRelevantVarsIgnoring :: Free' a VarSet => IgnoreSorts -> a -> VarSet
- allRelevantOrUnusedVars :: Free' a VarSet => a -> VarSet
- allRelevantOrUnusedVarsIgnoring :: Free' a VarSet => IgnoreSorts -> a -> VarSet
- freeIn :: Free a => Nat -> a -> Bool
- freeInIgnoringSorts :: Free a => Nat -> a -> Bool
- isBinderUsed :: Free a => Abs a -> Bool
- relevantIn :: Free a => Nat -> a -> Bool
- relevantInIgnoringSortAnn :: Free a => Nat -> a -> Bool
- data Occurrence
  - = NoOccurrence
  - | Irrelevantly
  - | StronglyRigid
  - | Unguarded
  - | WeaklyRigid
  - | Flexible MetaSet
  - | Unused
- occurrence :: FreeV a => Nat -> a -> Occurrence
- closed :: Free' a All => a -> Bool
- freeVars :: (Monoid c, Singleton Variable c, Free' a c) => a -> c
- freeVars' :: (Free' a c, Monoid c) => a -> FreeM c

# Documentation

data FreeVars #

Free variables of a term, (disjointly) partitioned into strongly and and weakly rigid variables, flexible variables and irrelevant variables.

Constructors

FV |
Fields stronglyRigidVars :: VarSet Variables under only and at least one inductive constructor(s). unguardedVars :: VarSet 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. weaklyRigidVars :: VarSet Ordinary rigid variables, e.g., in arguments of variables. flexibleVars :: IntMap MetaSet 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. irrelevantVars :: VarSet Variables in irrelevant arguments and under a `DontCare`, i.e., in irrelevant positions. unusedVars :: VarSet Variables in `UnusedArg`uments.

Instances

Eq FreeVars # |
Methods (==) :: FreeVars -> FreeVars -> Bool # (/=) :: FreeVars -> FreeVars -> Bool #
Show FreeVars # |
Methods showsPrec :: Int -> FreeVars -> ShowS # show :: FreeVars -> String # showList :: [FreeVars] -> ShowS #
Semigroup FreeVars # | Free variable sets form a monoid under `union`.
Methods (<>) :: FreeVars -> FreeVars -> FreeVars # sconcat :: NonEmpty FreeVars -> FreeVars # stimes :: Integral b => b -> FreeVars -> FreeVars #
Monoid FreeVars # |
Methods mempty :: FreeVars # mappend :: FreeVars -> FreeVars -> FreeVars # mconcat :: [FreeVars] -> FreeVars #
Null FreeVars # |
Methods empty :: FreeVars # null :: FreeVars -> Bool #
Singleton Variable FreeVars # |
Methods singleton :: Variable -> FreeVars #

type Free a = Free' a Any #

class Free' a c where #

Gather free variables in a collection.

Minimal complete definition

freeVars'

Methods

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

Instances

Free' EqualityView c # |
Methods freeVars' :: EqualityView -> FreeM c #
Free' Clause c # |
Methods freeVars' :: Clause -> FreeM c #
Free' LevelAtom c # |
Methods freeVars' :: LevelAtom -> FreeM c #
Free' PlusLevel c # |
Methods freeVars' :: PlusLevel -> FreeM c #
Free' Level c # |
Methods freeVars' :: Level -> FreeM c #
Free' Sort c # |
Methods freeVars' :: Sort -> FreeM c #
Free' Term c # |
Methods freeVars' :: Term -> FreeM c #
Free' Candidate c # |
Methods freeVars' :: Candidate -> FreeM c #
Free' DisplayTerm c # |
Methods freeVars' :: DisplayTerm -> FreeM c #
Free' DisplayForm c # |
Methods freeVars' :: DisplayForm -> FreeM c #
Free' Constraint c # |
Methods freeVars' :: Constraint -> FreeM c #
Free' a c => Free' [a] c # |
Methods freeVars' :: [a] -> FreeM c #
Free' a c => Free' (Maybe a) c # |
Methods freeVars' :: Maybe a -> FreeM c #
Free' a c => Free' (Dom a) c # |
Methods freeVars' :: Dom a -> FreeM c #
Free' a c => Free' (Arg a) c # |
Methods freeVars' :: Arg a -> FreeM c #
Free' a c => Free' (Tele a) c # |
Methods freeVars' :: Tele a -> FreeM c #
Free' a c => Free' (Type' a) c # |
Methods freeVars' :: Type' a -> FreeM c #
Free' a c => Free' (Abs a) c # |
Methods freeVars' :: Abs a -> FreeM c #
Free' a c => Free' (Elim' a) c # |
Methods freeVars' :: Elim' a -> FreeM c #
(Free' a c, Free' b c) => Free' (a, b) c # |
Methods freeVars' :: (a, b) -> FreeM c #

type FreeV a = Free' a FreeVars #

type FreeVS a = Free' a VarSet #

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 # |
Methods (==) :: IgnoreSorts -> IgnoreSorts -> Bool # (/=) :: IgnoreSorts -> IgnoreSorts -> Bool #
Show IgnoreSorts # |
Methods showsPrec :: Int -> IgnoreSorts -> ShowS # show :: IgnoreSorts -> String # showList :: [IgnoreSorts] -> ShowS #

runFree :: (Monoid c, Free' a c) => SingleVar c -> IgnoreSorts -> a -> c #

rigidVars :: FreeVars -> VarSet #

Rigid variables: either strongly rigid, unguarded, or weakly rigid.

relevantVars :: FreeVars -> VarSet #

All but the irrelevant variables.

allVars :: FreeVars -> VarSet #

`allVars fv` includes irrelevant variables.

allFreeVars :: Free' a VarSet => a -> VarSet #

Collect all free variables.

allRelevantVars :: Free' a VarSet => a -> VarSet #

Collect all relevant free variables, excluding the "unused" ones.

allRelevantVarsIgnoring :: Free' a VarSet => IgnoreSorts -> a -> VarSet #

Collect all relevant free variables, excluding the "unused" ones, possibly ignoring sorts.

allRelevantOrUnusedVars :: Free' a VarSet => a -> VarSet #

Collect all relevant free variables.

allRelevantOrUnusedVarsIgnoring :: Free' a VarSet => IgnoreSorts -> a -> VarSet #

Collect all relevant free variables, possibly ignoring sorts.

freeIn :: Free a => Nat -> a -> Bool #

freeInIgnoringSorts :: Free a => Nat -> a -> Bool #

isBinderUsed :: Free a => Abs a -> Bool #

Is the variable bound by the abstraction actually used?

relevantIn :: Free a => Nat -> a -> Bool #

relevantInIgnoringSortAnn :: Free a => Nat -> a -> Bool #

data Occurrence #

Constructors

NoOccurrence |
Irrelevantly |
StronglyRigid | Under at least one and only inductive constructors.
Unguarded | In top position, or only under inductive record constructors.
WeaklyRigid | In arguments to variables and definitions.
Flexible MetaSet | In arguments of metas.
Unused |

Instances

Eq Occurrence # |
Methods (==) :: Occurrence -> Occurrence -> Bool # (/=) :: Occurrence -> Occurrence -> Bool #
Show Occurrence # |
Methods showsPrec :: Int -> Occurrence -> ShowS # show :: Occurrence -> String # showList :: [Occurrence] -> ShowS #

occurrence :: FreeV a => Nat -> a -> Occurrence #

Compute an occurrence of a single variable in a piece of internal syntax.

closed :: Free' a All => a -> Bool #

Is the term entirely closed (no free variables)?

freeVars :: (Monoid c, Singleton Variable c, Free' a c) => a -> c #

Doesn't go inside solved metas, but collects the variables from a metavariable application `X ts` as `flexibleVars`.

freeVars' :: (Free' a c, Monoid c) => a -> FreeM c #