在简单类型的lambda演算的类型检查器中间,我有这个:
check Γ (lam τ′ E) (τ₁ ↣ τ₂) with τ′ T≟ τ₁
check Γ (lam τ′ E) (τ₁ ↣ τ₂) | no ¬p = no lem
where
lem : ¬ Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂)
lem t = {!!}
洞的类型当然是⊥
。我希望通过t
上的模式匹配,我可以充分了解这种类型的推导,以证明它是荒谬的。但是,如果我对t
进行案例分析,我会得到:
lem : ¬ Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂)
lem (tLam t) = ?
τ′ != τ₁ of type Type
when checking that the pattern tLam t has type
Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂)
是的,这一点非常重要的是要证明没有什么可以代替t
而写,因为τ
不匹配......但我怎么告诉Agda ?
作为参考,这里是完整的(简化但完整的)模块:
open import Data.Nat
open import Data.Fin
open import Data.Vec
open import Function using (_∘_)
data Type : Set where
_↣_ : Type → Type → Type
infixr 20 _↣_
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
arr-injˡ : ∀ {τ τ′ τ₂ τ₂′} → τ ↣ τ₂ ≡ τ′ ↣ τ₂′ → τ ≡ τ′
arr-injˡ refl = refl
arr-injʳ : ∀ {τ τ′ τ″} → τ ↣ τ′ ≡ τ ↣ τ″ → τ′ ≡ τ″
arr-injʳ refl = refl
_T≟_ : (τ τ′ : Type) → Dec (τ ≡ τ′)
(τ₁ ↣ τ₂) T≟ (τ₁′ ↣ τ₂′) with τ₁ T≟ τ₁′
(τ₁ ↣ τ₂) T≟ (τ₁′ ↣ τ₂′) | no ¬p = no (¬p ∘ arr-injˡ)
(τ₁ ↣ τ₂) T≟ (.τ₁ ↣ τ₂′) | yes refl with τ₂ T≟ τ₂′
(τ₁ ↣ τ₂) T≟ (.τ₁ ↣ .τ₂) | yes refl | yes refl = yes refl
(τ₁ ↣ τ₂) T≟ (.τ₁ ↣ τ₂′) | yes refl | no ¬p = no (¬p ∘ arr-injʳ)
data Expr (n : ℕ) : Set where
lam : (τ : Type) → Expr (suc n) → Expr n
Ctxt : ℕ → Set
Ctxt = Vec Type
data _⊢_∷_ : ∀ {n} → Ctxt n → Expr n → Type → Set where
tLam : ∀ {n} {Γ : Ctxt n} {τ E τ′} → ((τ ∷ Γ) ⊢ E ∷ τ′) → (Γ ⊢ lam τ E ∷ τ ↣ τ′)
⊢-inj : ∀ {n Γ} {E : Expr n} → ∀ {τ τ′} → Γ ⊢ E ∷ τ → Γ ⊢ E ∷ τ′ → τ ≡ τ′
⊢-inj {E = lam τ E} (tLam t) (tLam t′) = cong (_↣_ τ) (⊢-inj t t′)
module Infer where
check : ∀ {n} Γ → (E : Expr n) → ∀ τ → Dec (Γ ⊢ E ∷ τ)
check Γ (lam τ′ E) (τ₁ ↣ τ₂) with τ′ T≟ τ₁
check Γ (lam τ′ E) (.τ′ ↣ τ₂) | yes refl with check (τ′ ∷ Γ) E τ₂
check Γ (lam τ′ E) (.τ′ ↣ τ₂) | yes refl | yes E∷τ₂ = yes (tLam E∷τ₂)
check Γ (lam τ′ E) (.τ′ ↣ τ₂) | yes refl | no ¬t = no lem
where
lem : ¬ Γ ⊢ lam τ′ E ∷ (τ′ ↣ τ₂)
lem (tLam t) = ¬t t
check Γ (lam τ′ E) (τ₁ ↣ τ₂) | no ¬p = no lem
where
lem : ¬ Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂)
lem (tLam t) = ?
答案 0 :(得分:2)
好吧,我不确定这是否是最好的解决方案,但是当遇到这样的问题时,你通常会查看上下文,看看你可以在哪里获得⊥
并尝试证明一个导致的属性它。
特别是,您无法在t
上进行模式匹配,因为正如您所说,τ′ ≠ τ₁
(这是您的假设之一)。但是看一下tLam
的定义,应该可以证明:
lam-T≡ : ∀ {n τ₁ τ₂ τ′} {Γ : Ctxt n} {E : Expr (suc n)} →
Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂) → τ′ ≡ τ₁
事实上,情况确实如此:
lam-T≡ (tLam t) = refl
这为您提供¬p
需要的证据:
lem : ¬ Γ ⊢ lam τ′ E ∷ (τ₁ ↣ τ₂)
lem t = ¬p (lam-T≡ t)