We collect here some coding standards.
Only import what is necessary. Avoid global open and prefer local open statements.
Use the standard and categories libraries instead of reinventing the wheel.
Use indentation level 2. Instead of
Functor-Jⱽ.F-resp-≈ (Monad.F₀ VMonad Γ A) {ψ} {Ω} {Δ} {Ξ} {ρ} {τ} {ι} {μ} ξᵛʳ ξᵐʳ {t} {u} ξ =
begin⟨ Term-setoid Θ _ _ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛʳ ]ᵛʳ t) ≈⟨ []ᵛʳ-resp-≈ ξ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛʳ ]ᵛʳ u)
≈⟨ []ᵛʳ-resp-≡ᵛʳ ([,]ᵛʳ-resp-≡ᵛʳ (λ x → refl) λ x → ρ-resp-≡ {ρ = var-inr} (ξᵛʳ x)) ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (τ x₁)) ]ᵛʳ ]ᵛʳ u) ∎
you should write
Functor-Jⱽ.F-resp-≈ (Monad.F₀ VMonad Γ A) {ψ} {Ω} {Δ} {Ξ} {ρ} {τ} {ι} {μ} ξᵛʳ ξᵐʳ {t} {u} ξ =
begin⟨ Term-setoid Θ _ _ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛʳ ]ᵛʳ t)
≈⟨ []ᵛʳ-resp-≈ ξ ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (ρ x₁)) ]ᵛʳ ]ᵛʳ u)
≈⟨ []ᵛʳ-resp-≡ᵛʳ ([,]ᵛʳ-resp-≡ᵛʳ (λ x → refl) λ x → ρ-resp-≡ {ρ = var-inr} (ξᵛʳ x)) ⟩
([ [ (λ x₁ → var-inl x₁) , (λ x₁ → var-inr (τ x₁)) ]ᵛʳ ]ᵛʳ u) ∎
or something similar that doesn't produce exceedingly long lines with unecessary indentation.
- Use full names:
RelativeMonadinstead ofRelMon,RelativeMorphisminstead ofRelMorph. Abbreviations should be use very sparingly. - We use subscripts to indicate entities, as follows:
ᵛfor variable renamingᵐfor metavariable renamingˢfor substititionⁱfor instantiation
- Composition of entities is written as
∘ˣwherexis a supscript indicating the kind, e.g.,σ ∘ˢ τis composition of subtitutions. There are also mixed compositionsʸ∘ˣwhich compose an entity of kindywith an entitiy of kindx. - The action of
fon a termtis written as[ f ]ˣ twherexis a supscript indicating the kind off. For example,[ σ ]ˢ tis the action of the substitutionσon termt. - A theorem explaining how an action interacts with composition are named
[∘ˣ]or[ˣ∘ʸ]. - A theorem stating that an action
[]ˣrespects equality≈ʸare named[]ˣ-resp-≈ʸ.
Given functors I F : ℂ → 𝔻, let RelativeMonad I F be the category whose objects are
relative monad structures on (I, F) and the morphisms are relative monad morphisms between them.
The ingridients:
- A set of types
Ty. - A category
VCtxof variable contexts and renamings. The category has finite coproducts. - A category
MCtxof metavariable contexts and renamings. The category has finite coproducts. - A coproduct-preserving functor
Jᵛ : VCtx → Set^TywhereJᵛ Γ Ais thought of as variables of typeAin contextΓ - A coproduct-preserving functor
Jᵐ : VCtx → Set^(VCtx × Ty), whereJᵐ Θ (Δ, A)is thought of as metavariables of arityΔand typeAin metacontextΘ. - A functor
Term : MCtx → VCtx → Set^Ty, whereTerm Θ Γ Ais thought of as the set of terms of typeAin metacontextΘand contextΓ. - A functor
MCtx → RelativeMonad Jᵛ TᵛwhereTᵛ : MCtx → VCtx → Set^TyisTᵛ Θ Γ A := Term Θ Γ A. - A functor
VCtx → RelativeMonad Jᵐ TᵐwhereTᵐ : VCtx → MCtx → Set^(VCtx × Ty)isTᵐ Θ Γ (Δ, A) = Term Θ (Γ + Δ) A. - For every
f : Jⱽ Γ → Tᵛ Θ Γ'we can definehat f : Tᵐ Γ → Tᵐ Γ'and it is aJᵐ-relative monad morphism - For every
I : Jᵐ Θ → Tᵐ Θ'we can definehat I : Tᵛ Θ → Tᵛ Θ'and it is aJᵛ-relative monad morphism
The syntactic structure is recovered from the above category-theoretic ingridients as follows:
- Types are the elements of
Ty. - Variable contexts are the objects of
VCtx, variable renamings are the morphisms. - Metavariable contexts are the objects of
MCtx, metavariable renamings are the morphisms. x : A ∈ Γisx ∈ Jⱽ Γ AM : [ Δ , A ]∈ ΘisM ∈ Jᴹ Θ (Δ, A)Θ ; Γ ⊢ t : Aist ∈ Term Θ Γ A- a substitution
σ : Γ ⇒ˢ Θ ⊕ Δis a morphismσ : Jᵛ Γ → Tᵛ Θ ΔinSet^Ty. - the renaming action
[ ρ ]ʳ : Term Θ Γ → Term Θ ΔisTerm Θ ρ - the substitution action
[ σ ]ˢ : Term Θ Γ → Term Θ Δis the Kleisli extension ofσ - an instantiation
I : Θ ⇒ⁱ Ξ ⊕ Γis a morphismI : Jᵐ Θ → Tᵐ Γ ΞinSet^(VCtx × Ty) - the instantiation action
[ I ]ⁱ : Term Θ Γ → Term Ξ Γis (please fill in) - extension
⇑ʳarises from the coproduct structure onVCtx - extension
⇑ˢarises from the coproduct structure onTerms(category whose objects are the contexts, and whose morphisms are ) - extension
⇑ⁱarises from (please fill in)
In this project we are aiming to formalize simple type theories in Agda. We may proceed along two axes, generality and meta-analysis.
Generality is about how large a class of type theories we encompass. There are many ways to measure "generality", but here is one that ought to work well and allow us to proceed in steps.
Parameterized by:
- a family of term symbols, each having an arity (a set, or a number)
- a family of equational axioms
Γ ⊢ ℓ ≡ r, see below
Expressions:
- terms
s,t:
Judgement forms:
| Form | Intent |
|---|---|
Γ ⊢ t |
t is a term in context Γ = (x₁, ..., xᵢ) |
Γ ⊢ s ≡ t |
s and t are equal terms in context Γ |
Examples: monoid, group, (fintarily branching) inductive types, ring, R-module (for a fixed R).
Parameterized by:
- a set of sorts
- a family of term symbols, each having an arity
(σ₁, ..., σᵢ) → τwhereσ's andτare sorts. - a family of equational axioms
Γ ⊢ ℓ ≡ r : σ, see below
Expressions:
- terms
s,t
Judgement forms:
| Form | Intent |
|---|---|
Γ ⊢ t |
t is a term in context Γ = (x₁, ..., xᵢ) |
Γ ⊢ s ≡ t : σ |
s and t are equal terms of sort σ in context Γ |
Examples: module, directed graph, mutually recursive (finitarily branching) inductive types.
These extend many-sorted algebraic theory in two ways:
- instead of having an amorphous set of sorts, we have types which are generated using type symbols
- term symbols may bind variables (e.g.,
λ-abstraction)
Parameterized by:
- a family of type symbols, each having an arity (a number, or a set)
- a family of term symbols, each having a formation rule (to be determined precisely what that is)
- a family of equational axioms
Γ ⊢ ℓ ≡ r : σ, see below
Syntactic classes:
- types
σ,τ, generated by type symbols - terms
s,tgenerated by variables, and term symbols applied to arguments - arguments are types and (possibly abstracted) terms
Judgement forms:
| Form | Intent |
|---|---|
Γ ⊢ t : τ |
t is a term of type τ in context Γ = (x₁:σ₁, …, xᵢ:σᵢ) |
Γ ⊢ s ≡ t : τ |
s and t are equal terms of type τ in context Γ |
Example: untyped λ-calculus, simply typed λ-calculus
These are like simple type theories, but we also allow types to take term arguments. However, types may not contain any free variables. This allows us to form types that depende on terms, such as a subtype { x : τ | ϕ } where x : τ ⊢ ϕ : bool -- here x is bound in the type.
Parameterized by:
- a family of type symbols, each having a formation rule (to be determined)
- a family of term symbols, each having a formation rule (to be determined)
- a family of equational term axioms
Γ ⊢ ℓ ≡ r : σ, see below - a family of equational type axioms
Γ ⊢ σ ≡ τ, see below
Syntactic classes:
- types
σ,τ, generated by type symbols appied to arguments - terms
s,tgenerated by variables, and term symbols applied to term arguments - arguments are types and (possibly abstracted) terms
Important: types may not contain any free variables!
Judgement forms:
| Form | Intent |
|---|---|
σ ≡ τ |
σ and τ are equal types |
Γ ⊢ t : τ |
t is a term of type τ in context Γ = (x₁:σ₁, …, xᵢ:σᵢ) |
Γ ⊢ s ≡ t : τ |
s and t are equal terms of type τ in context Γ |
Example: internal logic of an elementary topos
We may pursue several directions of study.
Definitions can be given at different levels of concreteness. For example, we may have raw terms and types, and a separate judgement that such raw entities are well formed, or we have a single definition of terms and types that prevents us from ever generating an ill-typed term.
We can prove theorems, such as uniqueness of typing, substitution lemmas, admissibility of substitutions, etc.
We can define categorical semantics and show it to be sound.
We can show that the semantics is complete by constructing the initial models.