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

Agda.TypeChecking.Rewriting

Description

Rewriting with arbitrary rules.

The user specifies a relation symbol by the pragma  {-# BUILTIN REWRITE rel #-}  where rel should be of type Δ → (lhs rhs : A) → Set i.

Then the user can add rewrite rules by the pragma  {-# REWRITE q #-}  where q should be a closed term of type Γ → rel us lhs rhs.

We then intend to add a rewrite rule  Γ ⊢ lhs ↦ rhs : B  to the signature where B = A[us/Δ].

To this end, we normalize lhs, which should be of the form  f ts  for a Def-symbol f (postulate, function, data, record, constructor). Further, FV(ts) = dom(Γ). The rule q :: Γ ⊢ f ts ↦ rhs : B is added to the signature to the definition of f.

When reducing a term Ψ ⊢ f vs is stuck, we try the rewrites for f, by trying to unify vs with ts. This is for now done by substituting fresh metas Xs for the bound variables in ts and checking equality with vs  Ψ ⊢ (f ts)[XsΓ] = f vs : B[XsΓ]  If successful (no open metas/constraints), we replace f vs by rhs[Xs/Γ] and continue reducing.

Synopsis

Documentation

Check that the name given to the BUILTIN REWRITE is actually a relation symbol. I.e., its type should be of the form Δ → (lhs : A) (rhs : B) → Set ℓ. Note: we do not care about hiding/non-hiding of lhs and rhs.

data RelView Source #

Deconstructing a type into Δ → t → t' → core.

Constructors

 RelView FieldsrelViewTel :: TelescopeThe whole telescope Δ, t, t'.relViewDelta :: ListTelΔ.relViewType :: Dom Typet.relViewType' :: Dom Typet'.relViewCore :: Typecore.

Deconstructing a type into Δ → t → t' → core. Returns Nothing if not enough argument types.

Add q : Γ → rel us lhs rhs as rewrite rule  Γ ⊢ lhs ↦ rhs : B  to the signature where B = A[us/Δ]. Remember that rel : Δ → A → A → Set i, so rel us : (lhs rhs : A[us/Δ]) → Set i.

Append rewrite rules to a definition.

rewriteWith t f es rew where f : t tries to rewrite f es with rew, returning the reduct if successful.

rewrite b v rules es tries to rewrite v applied to es with the rewrite rules rules. b is the default blocking tag.

Auxiliary functions

class NLPatVars a where Source #

Minimal complete definition

nlPatVarsUnder

Instances
 Source # Instance detailsDefined in Agda.TypeChecking.Rewriting Methods Source # Instance detailsDefined in Agda.TypeChecking.Rewriting Methods (Foldable f, NLPatVars a) => NLPatVars (f a) Source # Instance detailsDefined in Agda.TypeChecking.Rewriting MethodsnlPatVarsUnder :: Int -> f a -> IntSet Source #nlPatVars :: f a -> IntSet Source #

class GetMatchables a where Source #

Get all symbols that a rewrite rule matches against

Methods

getMatchables :: a -> [QName] Source #

Instances
 Source # Instance detailsDefined in Agda.TypeChecking.Rewriting Methods Source # Instance detailsDefined in Agda.TypeChecking.Rewriting Methods (Foldable f, GetMatchables a) => GetMatchables (f a) Source # Instance detailsDefined in Agda.TypeChecking.Rewriting MethodsgetMatchables :: f a -> [QName] Source #

Orphan instances

 Source # Instance details MethodsfreeVars' :: IsVarSet c => NLPType -> FreeM c Source # Source # Instance details MethodsfreeVars' :: IsVarSet c => NLPat -> FreeM c Source #