open import Definition.Typechecking.Decidable.Assumptions
open import Definition.Typed.Restrictions
open import Graded.Modality
module Definition.Typed.Decidable
{a} {M : Set a}
{𝕄 : Modality M}
{R : Type-restrictions 𝕄}
(as : Assumptions R)
where
open Assumptions as
open Type-restrictions R
open import Definition.Untyped M
open import Definition.Typed R
open import Definition.Typed.Consequences.Unfolding R
open import Definition.Typed.Properties R
open import Definition.Typed.Syntactic R
open import Definition.Typed.Variant
open import Definition.Typed.Well-formed R
open import Definition.Typechecking R
open import Definition.Typechecking.Soundness R
open import Definition.Typechecking.Completeness R
open import Definition.Typechecking.Decidable as
open import Tools.Function
open import Tools.Nat using (Nat)
import Tools.PropositionalEquality as PE
open import Tools.Product
open import Tools.Relation as Dec
private
variable
m n : Nat
∇ ∇′ : DCon (Term 0) m
φ : Unfolding _
Δ : Con Term n
Γ : Cons m n
A t : Term n
open import Definition.Typed.Decidable.Equality R _≟_ public
dec : ⊢ Γ → Checkable-type A → Dec (Γ ⊢ A)
dec ⊢Γ A =
Dec.map (soundness⇇Type ⊢Γ) (completeness⇇Type A) (dec⇇Type ⊢Γ A)
decTermᶜ : Γ ⊢ A → Checkable t → Dec (Γ ⊢ t ∷ A)
decTermᶜ ⊢A t = Dec.map soundness⇇ (completeness⇇ t) (dec⇇ t ⊢A)
decTermTypeᶜ : ⊢ Γ → Checkable-type A → Checkable t → Dec (Γ ⊢ t ∷ A)
decTermTypeᶜ ⊢Γ A t =
case dec ⊢Γ A of λ where
(yes ⊢A) → decTermᶜ ⊢A t
(no ¬⊢A) → no (¬⊢A ∘→ syntacticTerm)
decTermᵢ : ⊢ Γ → Inferable t → Dec (∃ λ A → Γ ⊢ t ∷ A)
decTermᵢ ⊢Γ t = Dec.map
(λ { (A , t⇉A) → A , (proj₂ (soundness⇉ ⊢Γ t⇉A))})
(λ { (A , ⊢t) → _ , (proj₁ (proj₂ (completeness⇉ t ⊢t)))})
(dec⇉ ⊢Γ t)
opaque
unfolding Trans
unfold-Checkable : CheckableDCon ∇ → CheckableDCon (Trans φ ∇)
unfold-Checkable ε =
ε
unfold-Checkable (∇ ∙ᶜᵗ[ t ∷ A ]) =
unfold-Checkable ∇ ∙ᶜᵗ[ t ∷ A ]
unfold-Checkable {φ = _ ⁰} (∇ ∙ᶜᵒ⟨ ok ⟩[ t ∷ A ]) =
unfold-Checkable ∇ ∙ᶜᵒ⟨ ok ⟩[ t ∷ A ]
unfold-Checkable {φ = _ ¹} (∇ ∙ᶜᵒ⟨ _ ⟩[ t ∷ A ]) =
unfold-Checkable ∇ ∙ᶜᵗ[ t ∷ A ]
decWfDCon : CheckableDCon ∇ → Dec (» ∇)
decWfDCon ε = yes ε
decWfDCon (∇ ∙ᶜᵒ⟨ ok ⟩[ t ∷ A ]) =
case (decWfDCon ∇ ×-dec′ λ »∇ →
dec (ε »∇) A) of λ where
(no not) → no λ where
∙ᵒ⟨ _ ⟩[ _ ∷ ⊢A ] → not (defn-wf (wf ⊢A) , ⊢A)
(yes (»∇ , ⊢A)) →
let cont = λ »∇′ →
let ⊢A′ = Unconditional.unfold-⊢ (λ _ → »∇′) ⊢A in
case decTermᶜ ⊢A′ t of λ where
(no not) → no λ where
∙ᵒ⟨ _ ⟩[ ⊢t ∷ _ ] → not ⊢t
(yes ⊢t) → yes ∙ᵒ⟨ ok ⟩[ ⊢t ∷ ⊢A ]
in
case PE.singleton unfolding-mode of λ where
(transitive , ≡transitive) →
cont (Transitive.unfold-» ≡transitive »∇)
(explicit , _) →
case decWfDCon (unfold-Checkable ∇) of λ where
(no not) → no λ where
∙ᵒ⟨ _ ⟩[ ⊢t ∷ _ ] → not $ defn-wf $ wfTerm ⊢t
(yes »∇′) → cont »∇′
decWfDCon (∇ ∙ᶜᵗ[ t ∷ A ]) =
case (decWfDCon ∇ ×-dec′ λ »∇ →
dec (ε »∇) A ×-dec′ λ ⊢A →
decTermᶜ ⊢A t) of λ where
(no not) → no λ where
∙ᵗ[ ⊢t ] → not (defn-wf (wfTerm ⊢t) , wf-⊢∷ ⊢t , ⊢t)
(yes (_ , _ , ⊢t)) → yes ∙ᵗ[ ⊢t ]
decWfCon : » ∇ → CheckableCon Δ → Dec (∇ »⊢ Δ)
decWfCon »∇ ε = yes (ε »∇)
decWfCon »∇ (Δ ∙ A) = case decWfCon »∇ Δ of λ where
(yes ⊢Δ) → case dec ⊢Δ A of λ where
(yes ⊢A) → yes (∙ ⊢A)
(no ⊬A) → no λ where
(∙ ⊢A) → ⊬A ⊢A
(no ⊬Δ) → no λ where
(∙ ⊢A) → ⊬Δ (wf ⊢A)
opaque
unfolding CheckableCons
decWfCons : CheckableCons Γ → Dec (⊢ Γ)
decWfCons (∇ , Γ) =
case decWfDCon ∇ of λ where
(no not) → no λ ⊢Γ → not (defn-wf ⊢Γ)
(yes »∇) → decWfCon »∇ Γ
decConTypeᶜ :
CheckableCons Γ → Checkable-type A → Dec (Γ ⊢ A)
decConTypeᶜ Γ A =
case decWfCons Γ of λ where
(yes ⊢Γ) → dec ⊢Γ A
(no ¬⊢Γ) → no (¬⊢Γ ∘→ wf)
decConTermTypeᶜ :
CheckableCons Γ → Checkable-type A → Checkable t → Dec (Γ ⊢ t ∷ A)
decConTermTypeᶜ Γ A t =
case decWfCons Γ of λ where
(yes ⊢Γ) → decTermTypeᶜ ⊢Γ A t
(no ¬⊢Γ) → no (¬⊢Γ ∘→ wfTerm)
decConTermᵢ :
CheckableCons Γ → Inferable t → Dec (∃ λ A → Γ ⊢ t ∷ A)
decConTermᵢ Γ t =
case decWfCons Γ of λ where
(yes ⊢Γ) → decTermᵢ ⊢Γ t
(no ¬⊢Γ) → no (¬⊢Γ ∘→ wfTerm ∘→ proj₂)