3
在類型檢查的簡單類型的演算中間的時候,我有這樣的:類型錯誤試圖模式匹配的東西,應該是荒謬反正
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) = ?