finished main code for Inference

This commit is contained in:
wadler 2018-05-18 11:12:04 -03:00
parent f0d0db6d57
commit d4a241ed25

View file

@ -184,14 +184,14 @@ module Raw where
⊢case : ∀ {Γ L M x N A}
→ Γ ⊢ L ↑ `
→ Γ ⊢ M ↓ A
→ Γ , x `: A ⊢ N ↓ A
→ Γ , x `: ` ⊢ N ↓ A
------------------------------------------
→ Γ ⊢ `case L [`zero`→ M |`suc x `→ N ] ↓ A
⊢μ : ∀ {Γ x N A}
→ Γ , x `: A ⊢ N ↓ A
-----------------------
→ Γ ⊢ `μ x `→ N ↓ A `→ A
→ Γ ⊢ `μ x `→ N ↓ A
↓↑ : ∀ {Γ M A}
→ Γ ⊢ M ↑ A
@ -252,7 +252,7 @@ module Raw where
return (ok A (Ax ⊢x))
synth Γ (L · M) =
do ok (A₀ `→ B) ⊢L ← synth Γ L
where _ → error "application of non-function"
where ok ` _ → error "cannot apply number"
ok A₁ ⊢M ← synth Γ M
yes refl ← return (A₀ ≟Tp A₁)
where no _ → error "types differ in application"
@ -263,7 +263,33 @@ module Raw where
synth Γ M =
error "untypable term"
inher Γ M A = {!!}
inher Γ (`λ x `→ N) (A `→ B) =
do ⊢N ← inher (Γ , x `: A) N B
return (⊢λ ⊢N)
inher Γ (`λ x `→ N) ` =
error "lambda cannot be natural"
inher Γ `zero ` =
do return ⊢zero
inher Γ `zero (A `→ b) =
error "zero cannot be function"
inher Γ (`suc M) ` =
do ⊢M ← inher Γ M `
return (⊢suc ⊢M)
inher Γ (`suc M) (A `→ B) =
error "suc cannot be function"
inher Γ `case L [`zero`→ M |`suc x `→ N ] A =
do ok ` ⊢L ← synth Γ L
where ok (_ `→ _) _ → error "cannot case on function"
⊢M ← inher Γ M A
⊢N ← inher (Γ , x `: `) N A
return (⊢case ⊢L ⊢M ⊢N)
inher Γ (`μ x `→ M) A =
do ⊢M ← inher (Γ , x `: A) M A
return (⊢μ ⊢M)
inher Γ M A₀ =
do ok A₁ ⊢M ← synth Γ M
yes refl ← return (A₀ ≟Tp A₁)
where no _ → error "inheritance and synthesis conflict"
return (↓↑ ⊢M)
\end{code}