Agda
Safe HaskellNone
LanguageHaskell2010

Agda.TypeChecking.Free.Generic

Description

Computing free variables of a term generically. Different queries can be specialized to the appropriate short-circuiting behavior and to only pass around the necessary data. A query can be written as an instance to the ComputeFree class which bundles all parameters of the generic traversal. The traversal itself is defined in the instance of the Free class. See Agda.TypeChecking.Free for examples of queries.

Background notes:

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

For further reading on semirings and semimodules for variable occurrence, see e.g. Conor McBrides "I got plenty of nuttin'" (Wadlerfest 2016). There, he treats the "quantity" dimension of variable occurrences.

The semiring has an additive operation for combining occurrences of subterms, and a multiplicative operation of representing function composition. E.g. if variable x appears o in term u, but u appears in context q in term t then occurrence of variable x coming from u is accounted for as q o in t.

Consider the example (λ{ x → (x,x)}) y:

  • Variable x occurs once unguarded in x.
  • It occurs twice unguarded in the aggregation x x
  • Inductive constructor , turns this into two strictly rigid occurrences.

If , is a record constructor, then we stay unguarded.

  • The function ({λ x → (x,x)}) provides a context for variable y. This context can be described as weakly rigid with quantity two.
  • The final occurrence of y is obtained as composing the context with the occurrence of y in itself (which is the unit for composition). Thus, y occurs weakly rigid with quantity two.

It is not a given that the context can be described in the same way as the variable occurrence. However, for the purpose of quantity it is the case and we obtain a semiring of occurrences with 0, 1, and even ω, which is an absorptive element for addition.

Synopsis

Documentation

class (ExpandCase (Collect r), Monoid (Collect r)) => ComputeFree r where Source #

Instances of ComputeFree are inputs to the generic traveral implemented by Free instances. The r type parameter denotes the Reader environment of the traversal.

Minimal complete definition

underBinders', variable'

Associated Types

type Collect r Source #

The result type of the traversal. Most commonly, this is either a newtype wrapper on Bool or some instantiation of StrictEndo from StrictEndo. The latter is used to efficiently accummulate sets or maps.

Methods

underBinders' :: Int -> r -> r Source #

Update the environment when going under some number of binders.

underConstructor' :: ConHead -> Elims -> r -> r Source #

Update the environment when descending into the spine of a constructor.

underModality' :: Maybe (Modality -> r -> r) Source #

Update the environment when going under a modality. Nothing has the identity action.

underFlexRig' :: Maybe (FlexRig -> r -> r) Source #

Update the environment when the rigidity of the current position changes, e.g. we switch to flexible mode when going into the spine of an unsolved metavariable. See the Free instances for details. Nothing has the identity action. NOTE: since Modality contains FlexRig information, if you implement a non-trivial FlexRig update, you must also implement a non-trivial modality update, in order to handle the FlexRig-s there!

underRelevance' :: Maybe (Relevance -> r -> r) Source #

Update the environment with relevance information. Nothing has the identity action. NOTE: since Modality contains relevances, if you implement non-trivial Relevance update, you must also implement a non-trivial modality update, to handle the relevances there!

variable' :: Int -> r -> Collect r Source #

Evaluating a single variable. NOTE: you have to disambiguate bound and free variables yourself! For example, when we collect all free variables in a set, we need to store an Int in the reader environment to keep track of the size of the local scope, which allows us to distinguish bound and free vars.

ignoreSorts' :: IgnoreSorts Source #

Do we want to skip over sorts of types?

class Free t where Source #

Methods

freeVars :: ComputeFree r => t -> Reader r (Collect r) Source #

Instances

Instances details
Free Clause Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Clause -> Reader r (Collect r) Source #

Free EqualityView Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Free Level Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Level -> Reader r (Collect r) Source #

Free Sort Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Sort -> Reader r (Collect r) Source #

Free Term Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Term -> Reader r (Collect r) Source #

Free Candidate Source # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Free CompareAs Source # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Free Constraint Source # 
Instance details

Defined in Agda.TypeChecking.Monad.Base

Free t => Free (Arg t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Arg t -> Reader r (Collect r) Source #

Free t => Free (Abs t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Abs t -> Reader r (Collect r) Source #

Free t => Free (Dom t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Dom t -> Reader r (Collect r) Source #

Free t => Free (PlusLevel' t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Free t => Free (Tele t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Tele t -> Reader r (Collect r) Source #

Free t => Free (Type' t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Type' t -> Reader r (Collect r) Source #

Free t => Free (Elim' t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Elim' t -> Reader r (Collect r) Source #

Free t => Free (SingleLevel' t) Source # 
Instance details

Defined in Agda.TypeChecking.Level

Free t => Free (List1 t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => List1 t -> Reader r (Collect r) Source #

Free t => Free (Maybe t) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => Maybe t -> Reader r (Collect r) Source #

Free t => Free [t] Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => [t] -> Reader r (Collect r) Source #

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

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => (a, b) -> Reader r (Collect r) Source #

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

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => (a, b, c) -> Reader r (Collect r) Source #

(Free a, Free b, Free c, Free d) => Free (a, b, c, d) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => (a, b, c, d) -> Reader r (Collect r) Source #

(Free a, Free b, Free c, Free d, Free e) => Free (a, b, c, d, e) Source # 
Instance details

Defined in Agda.TypeChecking.Free.Generic

Methods

freeVars :: ComputeFree r => (a, b, c, d, e) -> Reader r (Collect r) Source #