module A201801.AllList where
open import A201801.Prelude
open import A201801.Category
open import A201801.List
open import A201801.ListLemmas
data All {X} (P : X → Set) : List X → Set
where
∙ : All P ∙
_,_ : ∀ {Ξ A} → All P Ξ → P A → All P (Ξ , A)
maps : ∀ {X P Q} → {Ξ : List X}
→ (∀ {A} → P A → Q A) → All P Ξ
→ All Q Ξ
maps f ∙ = ∙
maps f (ξ , a) = maps f ξ , f a
get : ∀ {X P A} → {Ξ : List X}
→ All P Ξ → Ξ ∋ A
→ P A
get (ξ , a) zero = a
get (ξ , b) (suc i) = get ξ i
gets : ∀ {X P} → {Ξ Ξ′ : List X}
→ All P Ξ′ → Ξ′ ⊇ Ξ
→ All P Ξ
gets ξ done = ∙
gets (ξ , b) (drop η) = gets ξ η
gets (ξ , a) (keep η) = gets ξ η , a
infix 4 _⊇◇⟨_⟩_
data _⊇◇⟨_⟩_ {X P} : {Ξ Ξ′ : List X} → All P Ξ′ → Ξ′ ⊇ Ξ → All P Ξ → Set
where
done : ∙ ⊇◇⟨ done ⟩ ∙
drop : ∀ {A Ξ Ξ′} → {η : Ξ′ ⊇ Ξ} {a : P A} {ξ : All P Ξ} {ξ′ : All P Ξ′}
→ ξ′ ⊇◇⟨ η ⟩ ξ
→ ξ′ , a ⊇◇⟨ drop η ⟩ ξ
keep : ∀ {A Ξ Ξ′} → {η : Ξ′ ⊇ Ξ} {a : P A} {ξ : All P Ξ} {ξ′ : All P Ξ′}
→ ξ′ ⊇◇⟨ η ⟩ ξ
→ ξ′ , a ⊇◇⟨ keep η ⟩ ξ , a
id⊇◇ : ∀ {X P} → {Ξ : List X} {ξ : All P Ξ}
→ ξ ⊇◇⟨ id ⟩ ξ
id⊇◇ {ξ = ∙} = done
id⊇◇ {ξ = ξ , a} = keep id⊇◇
_∘⊇◇_ : ∀ {X P} → {Ξ Ξ′ Ξ″ : List X} {η₁ : Ξ′ ⊇ Ξ} {η₂ : Ξ″ ⊇ Ξ′}
{ξ : All P Ξ} {ξ′ : All P Ξ′} {ξ″ : All P Ξ″}
→ ξ′ ⊇◇⟨ η₁ ⟩ ξ → ξ″ ⊇◇⟨ η₂ ⟩ ξ′
→ ξ″ ⊇◇⟨ η₁ ∘ η₂ ⟩ ξ
𝜂₁ ∘⊇◇ done = 𝜂₁
𝜂₁ ∘⊇◇ drop 𝜂₂ = drop (𝜂₁ ∘⊇◇ 𝜂₂)
drop 𝜂₁ ∘⊇◇ keep 𝜂₂ = drop (𝜂₁ ∘⊇◇ 𝜂₂)
keep 𝜂₁ ∘⊇◇ keep 𝜂₂ = keep (𝜂₁ ∘⊇◇ 𝜂₂)
infix 4 _∋◇⟨_⟩_
data _∋◇⟨_⟩_ {X P} : ∀ {A} → {Ξ : List X} → All P Ξ → Ξ ∋ A → P A → Set
where
zero : ∀ {Ξ A} → {a : P A} {ξ : All P Ξ}
→ ξ , a ∋◇⟨ zero ⟩ a
suc : ∀ {B Ξ A} → {i : Ξ ∋ A} {a : P A} {b : P B} {ξ : All P Ξ}
→ ξ ∋◇⟨ i ⟩ a
→ ξ , b ∋◇⟨ suc i ⟩ a
ren∋◇ : ∀ {X P A} → {Ξ Ξ′ : List X} {η : Ξ′ ⊇ Ξ} {i : Ξ ∋ A}
{a : P A} {ξ : All P Ξ} {ξ′ : All P Ξ′}
→ ξ′ ⊇◇⟨ η ⟩ ξ → ξ ∋◇⟨ i ⟩ a
→ ξ′ ∋◇⟨ ren∋ η i ⟩ a
ren∋◇ done 𝑖 = 𝑖
ren∋◇ (drop 𝜂) 𝑖 = suc (ren∋◇ 𝜂 𝑖)
ren∋◇ (keep 𝜂) zero = zero
ren∋◇ (keep 𝜂) (suc 𝑖) = suc (ren∋◇ 𝜂 𝑖)