{-# OPTIONS --without-K --safe #-}
module Mints.Statics.Syntax where
open import Level renaming (suc to succ)
open import Lib
open import LibNonEmpty public
record HasO {i} (A : Set i) : Set i where
field
O : A → ℕ → ℕ
open HasO {{...}} public
record HasTr {i} (A : Set i) : Set i where
infixl 5 _∥_
field
_∥_ : A → ℕ → A
open HasTr {{...}} public
record Monotone {i j} (A : Set i) (B : Set j) : Set (i ⊔ j) where
infixl 4.5 _[_]
field
_[_] : A → B → A
open Monotone {{...}} public
infixl 4.2 _$_
infixl 4.5 _[|_]
mutual
Typ = Exp
data Exp : Set where
N : Typ
Π : Typ → Typ → Typ
Se : (i : ℕ) → Typ
□ : Typ → Typ
v : (x : ℕ) → Exp
ze : Exp
su : Exp → Exp
rec : (T : Typ) (s r t : Exp) → Exp
Λ : Exp → Exp
_$_ : Exp → Exp → Exp
box : Exp → Exp
unbox : ℕ → Exp → Exp
sub : Exp → Substs → Exp
infixl 3 _∘_
infixl 5 _;_
data Substs : Set where
I : Substs
wk : Substs
_∘_ : Substs → Substs → Substs
_,_ : Substs → Exp → Substs
_;_ : Substs → ℕ → Substs
Ctx : Set
Ctx = List Typ
Ctxs : Set
Ctxs = List⁺ Ctx
infixr 5 _∺_
_∺_ : Typ → Ctxs → Ctxs
T ∺ (Ψ ∷ Ψs) = (T ∷ Ψ) ∷ Ψs
infixr 4.5 _++⁻_
_++⁻_ : List Typ → Ctxs → Ctxs
_++⁻_ Ψ (Ψ′ ∷ Γ) = (Ψ ++ Ψ′) ∷ Γ
instance
ExpMonotone : Monotone Exp Substs
ExpMonotone = record { _[_] = sub }
p : Substs → Substs
p σ = wk ∘ σ
infixr 5 _⟶_
_⟶_ : Typ → Typ → Typ
S ⟶ T = Π S (T [ wk ])
_[|_] : Exp → Exp → Exp
t [| s ] = t [ I , s ]
q : Substs → Substs
q σ = (σ ∘ wk) , v 0
S-O : Substs → ℕ → ℕ
S-O σ 0 = 0
S-O I (suc n) = suc n
S-O wk (suc n) = suc n
S-O (σ , t) (suc n) = S-O σ (suc n)
S-O (σ ; m) (suc n) = m + S-O σ n
S-O (σ ∘ δ) (suc n) = S-O δ (S-O σ (suc n))
instance
SubstsHasO : HasO Substs
SubstsHasO = record { O = S-O }
S-Tr : Substs → ℕ → Substs
S-Tr σ 0 = σ
S-Tr I (suc n) = I
S-Tr wk (suc n) = I
S-Tr (σ , t) (suc n) = S-Tr σ (suc n)
S-Tr (σ ; m) (suc n) = S-Tr σ n
S-Tr (σ ∘ δ) (suc n) = S-Tr σ (suc n) ∘ S-Tr δ (O σ (suc n))
instance
SubstsHasTr : HasTr Substs
SubstsHasTr = record { _∥_ = S-Tr }
mutual
data Ne : Set where
v : (x : ℕ) → Ne
rec : (T : Nf) (z s : Nf) → Ne → Ne
_$_ : Ne → (n : Nf) → Ne
unbox : ℕ → Ne → Ne
data Nf : Set where
ne : (u : Ne) → Nf
N : Nf
Π : Nf → Nf → Nf
Se : (i : ℕ) → Nf
□ : Nf → Nf
ze : Nf
su : Nf → Nf
Λ : Nf → Nf
box : Nf → Nf
variable
S S′ S″ : Typ
T T′ T″ : Typ
Ψ Ψ′ Ψ″ : Ctx
Ψs Ψs′ : List Ctx
Γ Γ′ Γ″ : Ctxs
Δ Δ′ Δ″ : Ctxs
t t′ t″ : Exp
r r′ r″ : Exp
s s′ s″ : Exp
σ σ′ σ″ : Substs
τ τ′ τ″ : Substs
u u′ u″ : Ne
V V′ V″ : Ne
w w′ w″ : Nf
W W′ W″ : Nf
mutual
Ne⇒Exp : Ne → Exp
Ne⇒Exp (v x) = v x
Ne⇒Exp (rec T z s u) = rec (Nf⇒Exp T) (Nf⇒Exp z) (Nf⇒Exp s) (Ne⇒Exp u)
Ne⇒Exp (u $ n) = Ne⇒Exp u $ Nf⇒Exp n
Ne⇒Exp (unbox n u) = unbox n (Ne⇒Exp u)
Nf⇒Exp : Nf → Exp
Nf⇒Exp (ne u) = Ne⇒Exp u
Nf⇒Exp ze = ze
Nf⇒Exp (su w) = su (Nf⇒Exp w)
Nf⇒Exp (Λ w) = Λ (Nf⇒Exp w)
Nf⇒Exp N = N
Nf⇒Exp (Π S T) = Π (Nf⇒Exp S) (Nf⇒Exp T)
Nf⇒Exp (Se i) = Se i
Nf⇒Exp (□ w) = □ (Nf⇒Exp w)
Nf⇒Exp (box w) = box (Nf⇒Exp w)
infix 2 _∶_∈!_
data _∶_∈!_ : ℕ → Typ → Ctxs → Set where
here : 0 ∶ T [ wk ] ∈! T ∺ Γ
there : ∀ {n T S} → n ∶ T ∈! Γ → suc n ∶ T [ wk ] ∈! S ∺ Γ