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

Safe HaskellNone
LanguageHaskell98

Agda.TypeChecking.With

Synopsis

Documentation

splitTelForWith Source #

Arguments

:: Telescope

Δ context of types and with-arguments.

-> Type

Δ ⊢ t type of rhs.

-> [EqualityView]

Δ ⊢ as types of with arguments.

-> [Term]

Δ ⊢ vs with arguments. Output:

-> (Telescope, Telescope, Permutation, Type, [EqualityView], [Term])

(Δ₁,Δ₂,π,t',as',vs') where

Δ₁
part of context not needed for with arguments and their types.
Δ₂
part of context needed for with arguments and their types.
π
permutation from Δ to Δ₁Δ₂ as returned by splitTelescope.
Δ₁Δ₂ ⊢ t'
type of rhs under π
Δ₁ ⊢ as'
types with with-arguments depending only on Δ₁.
Δ₁ ⊢ vs'
with-arguments under π.

Split pattern variables according to with-expressions.

withFunctionType Source #

Arguments

:: Telescope

Δ₁ context for types of with types.

-> [Term]

Δ₁,Δ₂ ⊢ vs : raise Δ₂ as with and rewrite-expressions.

-> [EqualityView]

Δ₁ ⊢ as types of with and rewrite-expressions.

-> Telescope

Δ₁ ⊢ Δ₂ context extension to type with-expressions.

-> Type

Δ₁,Δ₂ ⊢ b type of rhs.

-> TCM (Type, Nat)

Δ₁ → wtel → Δ₂′ → b′ such that [vs/wtel]wtel = as and [vs/wtel]Δ₂′ = Δ₂ and [vs/wtel]b′ = b. Plus the final number of with-arguments.

Abstract with-expressions vs to generate type for with-helper function.

Each EqualityType, coming from a rewrite, will turn into 2 abstractions.

withArguments :: [Term] -> [EqualityView] -> [Term] Source #

From a list of with and rewrite expressions and their types, compute the list of final with expressions (after expanding the rewrites).

buildWithFunction Source #

Arguments

:: QName

Name of the parent function.

-> QName

Name of the with-function.

-> Type

Types of the parent function.

-> [NamedArg Pattern]

Parent patterns.

-> Permutation

Final permutation.

-> Nat

Number of needed vars.

-> Nat

Number of with expressions.

-> [SpineClause]

With-clauses.

-> TCM [SpineClause]

With-clauses flattened wrt. parent patterns.

Compute the clauses for the with-function given the original patterns.

stripWithClausePatterns Source #

Arguments

:: QName

Name of the parent function.

-> QName

Name of with-function.

-> Type

t type of the original function.

-> [NamedArg Pattern]

qs internal patterns for original function.

-> Permutation

π permutation taking vars(qs) to support(Δ).

-> [NamedArg Pattern]

ps patterns in with clause (eliminating type t).

-> TCM [NamedArg Pattern]

ps' patterns for with function (presumably of type Δ).

stripWithClausePatterns parent f t qs π ps = ps'
Δ
context bound by lhs of original function (not an argument).
f
name of with-function.
t
type of the original function.
qs
internal patterns for original function.
π
permutation taking vars(qs) to support(Δ).
ps
patterns in with clause (eliminating type t).
ps'
patterns for with function (presumably of type Δ).

Example:

record Stream (A : Set) : Set where
  coinductive
  constructor delay
  field       force : A × Stream A

record SEq (s t : Stream A) : Set where
  coinductive
  field
    ~force : let a , as = force s
                 b , bs = force t
             in  a ≡ b × SEq as bs

test : (s : Nat × Stream Nat) (t : Stream Nat) → SEq (delay s) t → SEq t (delay s)
~force (test (a     , as) t p) with force t
~force (test (suc n , as) t p) | b , bs = {!!}

With function:

  f : (t : Stream Nat) (w : Nat × Stream Nat) (a : Nat) (as : Stream Nat)
      (p : SEq (delay (a , as)) t) → (fst w ≡ a) × SEq (snd w) as

  Δ  = t a as p   -- reorder to bring with-relevant (= needed) vars first
  π  = a as t p → Δ
  qs = (a     , as) t p ~force
  ps = (suc n , as) t p ~force
  ps' = (suc n) as t p

Resulting with-function clause is:

  f t (b , bs) (suc n) as t p

Note: stripWithClausePatterns factors ps through qs, thus

  ps = qs[ps']

where [..] is to be understood as substitution. The projection patterns have vanished from ps' (as they are >

Note:Def" class="lincodeTypeChee> (as tl#t:Phase">Phase-(d colspan="2"> jse">ypeChhhhhhhhhd by lhs801; b & -> b empty with clhhhhd-Base.hlan="2">Bool)ss="link">Source (phlan="2">tbly ofase">Phase-lass="caption">M"Agda-Syneneeded>

Sourc">Pr splitt>ypeChhhhethods">e="cies/basd>Sourceclass="sr/baseihee> (phlan /a> a) stitu#t:UnquoteM">Unquocrete-Namess"Agda-TypeCheckince t sd>M">Unqutd can cltors.htm>

t>ypeCel">e="ciSEq (del/a> Em hr-> m +4t:Aspect">Aspect Int/usr/sharasUnquoruieral">Lit >14gda-TypeChec/ghc-dtml#tame.ht field forhreamlam Nat) (w : Nqghcoass="link"> classsssssssss. The.nqurefl/)Problem,l">Lit >14f hrefl/ : S >14f >TCMps'14f,">
  • classsssssssss. The.nqurefl/)Problem,l">Lit >14f hrefl/ : S >14f >TCMps'14f,">
  • //Ino"instancetract-NP"#v:withFunpan idProbl inC (C>tbly ofaontenIrc/Agda-TIntrialis="src/Agda-T. Thjavascriply oofaoitenIrc/Agda-TIntrialis="src/Agda-T. Thjavascriply oofaoitenIrc/Agda-TIntrialis="src/n -960; tml#t:Syref="Agda-Sontax-Position.html#t:PrintRange">Pri