基于this suggestion我试图使用order-preserving embeddings来表示项目中的重命名,我将需要两个级别的上下文(类型存在于类型变量类型和术语的kinding上下文中生活在术语变量类型的打字环境中)。在我的完整代码中,我替换完全实现的类型;但是在函数中保留了一个单孔,它对术语进行了类型重命名(因此这是为了重命名 type 变量)。下面是我尝试用最少的上下文重新创建漏洞。
这一切都以一个简单的List
上下文表示开始,具有简单的强化操作,可以轻松替换变量;以及基于以上链接的OPE实施:
open import Data.List
open import Data.List.Any
open Data.List.Any.Membership-≡ hiding (Kind)
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′) renaming (map to mapSum)
open import Function using (id)
open import Relation.Binary.PropositionalEquality
module Con where
Con : Set → Set
Con = List
Var : {A : Set} → A → Con A → Set
Var t Γ = t ∈ Γ
_∖_ : ∀ {A t} → (Γ : Con A) → Var t Γ → Con A
(._ ∷ Γ) ∖ here _ = Γ
(_ ∷ []) ∖ there ()
(a ∷ b ∷ Γ) ∖ there x = a ∷ (b ∷ Γ) ∖ x
∖-there : ∀ {A a b} {Γ : Con A} (x : Var b Γ) → (a ∷ Γ) ∖ there x ≡ a ∷ (Γ ∖ x)
∖-there {Γ = []} ()
∖-there {Γ = _ ∷ Γ} _ = refl
strengthen : ∀ {A a b} {Γ : Con A} → (x : Var a Γ) → (y : Var b Γ) → (a ≡ b) ⊎ (Var b (Γ ∖ x))
strengthen (here refl) (here refl) = inj₁ refl
strengthen (here _) (there y) = inj₂ y
strengthen {Γ = _ ∷ []} (there ())
strengthen {Γ = _ ∷ _ ∷ _} (there y) (here refl) = inj₂ (here refl)
strengthen {Γ = _ ∷ _ ∷ _} (there x) (there y) = mapSum id (lemma x) (strengthen x y)
where
lemma : ∀ {A a b c} {Γ : Con A} (x : Var a Γ) (y : Var b (Γ ∖ x)) → Var b ((c ∷ Γ) ∖ there x)
lemma {Γ = Γ} x y = subst (Var _) (sym (∖-there x)) (there y)
substVar : ∀ {A} {_⊢_ : Con A → A → Set}
→ (var : ∀ {a} {Γ : Con A} → Var a Γ → Γ ⊢ a)
→ ∀ {Γ : Con A} {a b}
→ (x : Var a Γ)
→ (e : (Γ ∖ x) ⊢ a)
→ (y : Var b Γ)
→ (Γ ∖ x) ⊢ b
substVar var x e y = [ (λ eq → subst _ eq e) , var ]′ (strengthen x y)
module OPE where
open Con
data _≼_ {A : Set} : Con A -> Con A -> Set where
done : [] ≼ []
keep : ∀ {Γ Δ a} -> Γ ≼ Δ -> (a ∷ Γ) ≼ (a ∷ Δ)
skip : ∀ {Γ Δ a} -> Γ ≼ Δ -> (a ∷ Γ) ≼ Δ
≼-refl : ∀ {A} {Γ : Con A} → Γ ≼ Γ
≼-refl {Γ = []} = done
≼-refl {Γ = x ∷ Γ} = keep ≼-refl
weak : ∀ {A} {a : A} {Γ} → (a ∷ Γ) ≼ Γ
weak = skip ≼-refl
ren : ∀ {A Γ Γ′} {a : A} → Γ′ ≼ Γ → Var a Γ → Var a Γ′
ren done ()
ren (keep σ) (here refl) = here refl
ren (keep σ) (there x) = there (ren σ x)
ren (skip σ) x = there (ren σ x)
ope-∖ : ∀ {A} {Γ Γ′} {t : A} → (x : Var t Γ) → (σ : Γ′ ≼ Γ) → (Γ′ ∖ ren σ x) ≼ (Γ ∖ x)
ope-∖ (here refl) (keep σ) = σ
ope-∖ {Γ = _ ∷ Γ} {x′ ∷ Γ′} (here refl) (skip σ) rewrite ∖-there {a = x′} (ren σ (here refl)) = skip (ope-∖ (here refl) σ)
ope-∖ {Γ = t ∷ Γ} {.t ∷ Γ′} (there x) (keep σ) rewrite ∖-there {a = t} (ren σ x) | ∖-there {a = t} x = keep (ope-∖ x σ)
ope-∖ {Γ = t ∷ Γ} {t′ ∷ Γ′} (there x) (skip σ) rewrite ∖-there {a = t′} (ren σ (there x)) = skip (ope-∖ (there x) σ)
然后我定义了一个表示范围广,知识渊博的System F类型的类型,并实现了类型变量的替换:
module _ where
open Con
open OPE
data Kind : Set where
⋆ : Kind
data _⊢_ (Γ : Con Kind) : Kind → Set where
tyvar : ∀ {κ} → (α : Var κ Γ) → Γ ⊢ κ
_⟶_ : (t₁ t₂ : Γ ⊢ ⋆) → Γ ⊢ ⋆
Pi : ∀ {κ′} → (κ : Kind) → (t : (κ ∷ Γ) ⊢ κ′) → Γ ⊢ κ′
renType : ∀ {κ} {Γ Γ′ : Con Kind} → Γ′ ≼ Γ → Γ ⊢ κ → Γ′ ⊢ κ
renType σ (tyvar α) = tyvar (ren σ α)
renType σ (t₁ ⟶ t₂) = renType σ t₁ ⟶ renType σ t₂
renType σ (Pi κ t) = Pi κ (renType (keep σ) t)
substType : ∀ {κ κ′} {Γ : Con Kind}
→ (β : Var κ′ Γ)
→ (t′ : (Γ ∖ β) ⊢ κ′)
→ (t : Γ ⊢ κ)
→ (Γ ∖ β) ⊢ κ
substType β t′ (tyvar α) = substVar tyvar β t′ α
substType β t′ (t₁ ⟶ t₂) = substType β t′ t₁ ⟶ substType β t′ t₂
substType {Γ = []} () t′ (Pi κ t)
substType {Γ = _ ∷ Γ} β t′ (Pi κ t) = Pi κ (substType (there β) (renType weak t′) t)
现在我终于有了一切来制定我的问题:如何证明substType
和ren
之间的以下关系?
substType-ren : ∀ {κ κ′ Γ Γ′}
→ (σ : Γ′ ≼ Γ)
→ (β : Var κ′ Γ)
→ (t′ : (Γ ∖ β) ⊢ κ′)
→ (t : Γ ⊢ κ)
→ substType (ren σ β) (renType (ope-∖ β σ) t′) (renType σ t) ≡ renType (ope-∖ β σ) (substType β t′ t)
substType-ren σ β t′ t = {!!}
到目前为止,为了显示我的工作,以下是我能够涵盖的案例:
strengthen-self : ∀ {A a} {Γ : Con A} (x : Var a Γ) → strengthen x x ≡ inj₁ refl
strengthen-self (here refl) = refl
strengthen-self {Γ = x ∷ []} (there ())
strengthen-self {Γ = _ ∷ _ ∷ Γ} (there x) rewrite strengthen-self x = refl
substVar-self : ∀ {A} {_⊢_ : Con A → A → Set}
→ (var : ∀ {a} {Γ : Con A} → Var a Γ → Γ ⊢ a)
→ ∀ {Γ : Con A} {a}
→ (x : Var a Γ)
→ (e : (Γ ∖ x) ⊢ a)
→ substVar var x e x ≡ e
substVar-self var x e rewrite strengthen-self x = refl
substType-ren : ∀ {κ κ′ Γ Γ′}
→ (σ : Γ′ ≼ Γ)
→ (β : Var κ′ Γ)
→ (t′ : (Γ ∖ β) ⊢ κ′)
→ (t : Γ ⊢ κ)
→ substType (ren σ β) (renType (ope-∖ β σ) t′) (renType σ t) ≡ renType (ope-∖ β σ) (substType β t′ t)
substType-ren σ (here refl) t′ (tyvar (here refl))
rewrite substVar-self tyvar (ren σ (here refl)) (renType (ope-∖ (here refl) σ) t′) = refl
substType-ren (keep σ) (here refl) t′ (tyvar (there α)) = refl
substType-ren (skip σ) (here refl) t′ (tyvar (there α)) = {!!}
substType-ren σ (there β) t′ (tyvar (here refl)) = {!!}
substType-ren σ (there β) t′ (tyvar (there α)) = {!!}
substType-ren σ β t′ (t₁ ⟶ t₂) = cong₂ _⟶_ (substType-ren σ β t′ t₁) (substType-ren σ β t′ t₂)
substType-ren σ β t′ (Pi κ t) = {!!}
此外,我现在有很多关于renType
如何{和1}将OPE提升为相同功能,或者ren
如何构成,或renType
是单射的;通常的嫌疑人,但到目前为止,在证明ren σ
时没有任何帮助。