{-# OPTIONS --allow-unsolved-metas #-}
module A201802.WIP.LR2e where
open import A201801.Prelude
open import A201801.Category
open import A201801.Fin
open import A201801.FinLemmas
open import A201801.Vec
open import A201801.VecLemmas
open import A201801.AllVec
open import A201802.LR0
open import A201802.LR0Lemmas
open import A201802.LR1
data IsVal {g} : Term g → Set
where
instance
val-LAM : ∀ {M} → IsVal (LAM M)
val-TRUE : IsVal TRUE
val-FALSE : IsVal FALSE
data EvCx (g : Nat) : Set
where
ec-[] : EvCx g
ec-fun-APP : EvCx g → Term g → EvCx g
ec-arg-APP : (M : Term g) → {{_ : IsVal M}} → EvCx g → EvCx g
ec-IF : EvCx g → Term g → Term g → EvCx g
_[_] : ∀ {g} → EvCx g → Term g → Term g
ec-[] [ M ] = M
ec-fun-APP E N [ M ] = APP (E [ M ]) N
ec-arg-APP N E [ M ] = APP N (E [ M ])
ec-IF E N O [ M ] = IF (E [ M ]) N O
infix 3 _↦_
data _↦_ {g} : Term g → Term g → Set
where
step-APP-LAM : ∀ {M N} → APP (LAM M) N ↦ CUT N M
step-IF-TRUE : ∀ {N O} → IF TRUE N O ↦ N
step-IF-FALSE : ∀ {N O} → IF FALSE N O ↦ O
step-cong : ∀ {M M′} → (E : EvCx g) → M ↦ M′
→ E [ M ] ↦ E [ M′ ]
infix 3 _⤅_
data _⤅_ {g} : Term g → Term g → Set
where
done : ∀ {M} → M ⤅ M
_⨾₁_ : ∀ {M M″ M′} → M ↦ M″ → M″ ⤅ M′
→ M ⤅ M′
_⨾ₙ_ : ∀ {g} → {M M″ M′ : Term g}
→ M ⤅ M″ → M″ ⤅ M′
→ M ⤅ M′
done ⨾ₙ M⤅M′ = M⤅M′
(M↦M‴ ⨾₁ M‴⤅M″) ⨾ₙ M″⤅M′ = M↦M‴ ⨾₁ (M‴⤅M″ ⨾ₙ M″⤅M′)
infix 3 _⇓_
_⇓_ : ∀ {g} → Term g → (M′ : Term g) → {{_ : IsVal M′}} → Set
M ⇓ M′ = M ⤅ M′
_⇓ : ∀ {g} → Term g → Set
M ⇓ = Σ (Term _) (\ M′ → {!Σ″ (IsVal M′) (\ {{iv}} → (M ⇓ M′) {{iv}})!})
mutual
tp↦ : ∀ {g M M′ A} → {Γ : Types g}
→ M ↦ M′ → Γ ⊢ M ⦂ A
→ Γ ⊢ M′ ⦂ A
tp↦ step-APP-LAM (app (lam 𝒟) ℰ) = cut ℰ 𝒟
tp↦ step-IF-TRUE (if 𝒟 ℰ ℱ) = ℰ
tp↦ step-IF-FALSE (if 𝒟 ℰ ℱ) = ℱ
tp↦ (step-cong E M↦M′) 𝒟 = cong-tp↦ E M↦M′ 𝒟
cong-tp↦ : ∀ {g M M′ A} → {Γ : Types g}
→ (E : EvCx g) → M ↦ M′ → Γ ⊢ E [ M ] ⦂ A
→ Γ ⊢ E [ M′ ] ⦂ A
cong-tp↦ ec-[] M↦M′ 𝒟 = tp↦ M↦M′ 𝒟
cong-tp↦ (ec-fun-APP E N) M↦M′ (app 𝒟 ℰ) = app (cong-tp↦ E M↦M′ 𝒟) ℰ
cong-tp↦ (ec-arg-APP N E) M↦M′ (app 𝒟 ℰ) = app 𝒟 (cong-tp↦ E M↦M′ ℰ)
cong-tp↦ (ec-IF E N O) M↦M′ (if 𝒟 ℰ ℱ) = if (cong-tp↦ E M↦M′ 𝒟) ℰ ℱ
tp⤅ : ∀ {g M M′ A} → {Γ : Types g}
→ M ⤅ M′ → Γ ⊢ M ⦂ A
→ Γ ⊢ M′ ⦂ A
tp⤅ done 𝒟 = 𝒟
tp⤅ (M↦M″ ⨾₁ M″⤅M′) 𝒟 = tp⤅ (M″⤅M′) (tp↦ M↦M″ 𝒟)
eval-IF : ∀ {g} → {M M′ N O : Term g}
→ M ⤅ M′
→ IF M N O ⤅ IF M′ N O
eval-IF {N = N} {O} done = done
eval-IF {N = N} {O} (M↦M″ ⨾₁ M″⤅M′) = step-cong (ec-IF ec-[] N O) M↦M″ ⨾₁ eval-IF M″⤅M′
eval-IF-TRUE : ∀ {g} → {M N O : Term g}
→ M ⤅ TRUE
→ IF M N O ⤅ N
eval-IF-TRUE M⤅TRUE = eval-IF M⤅TRUE ⨾ₙ (step-IF-TRUE ⨾₁ done)
eval-IF-FALSE : ∀ {g} → {M N O : Term g}
→ M ⤅ FALSE
→ IF M N O ⤅ O
eval-IF-FALSE M⤅FALSE = eval-IF M⤅FALSE ⨾ₙ (step-IF-FALSE ⨾₁ done)
private
module Impossible
where
sn : ∀ {M A} → ∙ ⊢ M ⦂ A
→ M ⇓
sn (var ())
sn (lam 𝒟) = {!LAM _ , ⟪ done ⟫!}
sn (app 𝒟 ℰ) = {!!}
sn true = {!TRUE , ⟪ done ⟫!}
sn false = {!FALSE , ⟪ done ⟫!}
sn _ = {!!}