HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

ModuleAgda-2.7.0.1Haskell2010

Agda.TypeChecking.With

  • 8 values
  • PackageAgda-2.7.0.1
  • Exports8
  • LanguageHaskell2010
  • LicenceMIT
  • SourceWith.hs
valuesplitTelForWith
  1. :: Telescope

    Δ context of types and with-arguments.

  2. -> Type

    Δ ⊢ t type of rhs.

  3. -> [Arg (Term, EqualityView)]

    Δ ⊢ vs : as with arguments and their types. Output:

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

    (Δ₁,Δ₂,π,t',vtys') where

    Δ₁

    part of context needed for with arguments and their types.

    Δ₂

    part of context not needed for with arguments and their types.

    π

    permutation from Δ to Δ₁Δ₂ as returned by

    splitTelescope

    .

    Δ₁Δ₂ ⊢ t'

    type of rhs under

    π

    Δ₁ ⊢ vtys'

    with-arguments and their types under

    π

    .

#

Split pattern variables according to with-expressions.

valuewithFunctionType
  1. :: Telescope

    Δ₁ context for types of with types.

  2. -> [Arg (Term, EqualityView)]

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

  3. -> Telescope

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

  4. -> Type

    Δ₁,Δ₂ ⊢ b type of rhs.

  5. -> [(Int, (Term, Term))]

    @Δ₁,Δ₂ ⊢ [(i,(u0,u1))] : b boundary.

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

valuebuildWithFunction
  1. :: [Name]

    Names of the module parameters of the parent function.

  2. -> QName

    Name of the parent function.

  3. -> QName

    Name of the with-function.

  4. -> Type

    Types of the parent function.

  5. -> Telescope

    Context of parent patterns.

  6. -> [NamedArg DeBruijnPattern]

    Parent patterns.

  7. -> Nat

    Number of module parameters in parent patterns

  8. -> Substitution

    Substitution from parent lhs to with function lhs

  9. -> Permutation

    Final permutation.

  10. -> Nat

    Number of needed vars.

  11. -> Nat

    Number of with expressions.

  12. -> List1 SpineClause

    With-clauses.

  13. -> TCM (List1 SpineClause)

    With-clauses flattened wrt. parent patterns.

#

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

valuestripWithClausePatterns
  1. :: [Name]

    cxtNames names of the module parameters of the parent function

  2. -> QName

    parent name of the parent function.

  3. -> QName

    f name of with-function.

  4. -> Type

    t top-level type of the original function.

  5. -> Telescope

    Δ context of patterns of parent function.

  6. -> [NamedArg DeBruijnPattern]

    qs internal patterns for original function.

  7. -> Nat

    npars number of module parameters in qs.

  8. -> Permutation

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

  9. -> [NamedArg Pattern]

    ps patterns in with clause (eliminating type t).

  10. -> TCM ([ProblemEq], [NamedArg Pattern])

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

#
stripWithClausePatterns cxtNames parent f t Δ qs np π ps = ps'

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 already in qs).

valuewithDisplayForm
  1. :: QName

    The name of parent function.

  2. -> QName

    The name of the with-function.

  3. -> Telescope

    Δ₁ The arguments of the with function before the with expressions.

  4. -> Telescope

    Δ₂ The arguments of the with function after the with expressions.

  5. -> Nat

    n The number of with expressions.

  6. -> [NamedArg DeBruijnPattern]

    qs The parent patterns.

  7. -> Permutation

    perm Permutation to split into needed and unneeded vars.

  8. -> Permutation

    lhsPerm Permutation reordering the variables in parent patterns.

  9. -> TCM DisplayForm
#

Construct the display form for a with function. It will display applications of the with function as applications to the original function. For instance,

    aux a b c
  

as

    f (suc a) (suc b) | c