2021-12-09 02:57:30 +00:00
|
|
|
|
-- {-# OPTIONS --allow-unsolved-metas #-}
|
2021-12-08 18:35:31 +00:00
|
|
|
|
|
2021-12-08 06:33:28 +00:00
|
|
|
|
module Project.Do where
|
|
|
|
|
|
|
|
|
|
open import Project.Definitions using (Letk; Kont; Exp; Value; State; Type; kont; halt; letk; clo; zero; suc; mkState; `_; `ℕ; _·_; _⇒_; _,_; _[_∶_])
|
|
|
|
|
open import Project.Util using (_$_)
|
|
|
|
|
|
|
|
|
|
data StepResult (A : Type) : Set where
|
|
|
|
|
part : State A → StepResult A
|
|
|
|
|
done : Value A → StepResult A
|
|
|
|
|
|
|
|
|
|
-- Apply the continuation to the value, resulting in a state.
|
|
|
|
|
do-kont : ∀ {Tv Tω} (L : Letk Tv Tω) → Value Tv → State Tω
|
|
|
|
|
do-kont {Tv} {Tω} (letk {Tc} Γ C E k) v =
|
|
|
|
|
let Γ′ = Γ , Tv in
|
|
|
|
|
let E′ = E [ Tv ∶ v ] in
|
|
|
|
|
mkState Tc Γ′ C E′ k
|
|
|
|
|
|
2021-12-09 02:57:30 +00:00
|
|
|
|
applykont : ∀ {Tv Tω} → Letk Tv Tω → Value Tv → StepResult Tω
|
|
|
|
|
applykont {Tv} (letk {Tc} Γ C E K) v =
|
|
|
|
|
part $ mkState Tc (Γ , Tv) C (E [ Tv ∶ v ]) K
|
|
|
|
|
|
|
|
|
|
chain-kont : ∀ {A B C} → Letk A B → Letk B C → Letk A C
|
|
|
|
|
chain-kont (letk Γ C E halt) b = letk Γ C E $ kont b
|
|
|
|
|
chain-kont (letk Γ C E (kont k)) b = letk Γ C E $ kont $ chain-kont k b
|
|
|
|
|
|
2021-12-08 18:35:31 +00:00
|
|
|
|
do-apply-kont : ∀ {A B Tω} → Value (A ⇒ B) → Value A → Letk B Tω → StepResult Tω
|
|
|
|
|
do-apply-kont (clo {Γ} {A} {B} body e) v k =
|
|
|
|
|
let Γ′ = Γ , A in
|
|
|
|
|
let E′ = e [ A ∶ v ] in
|
|
|
|
|
part $ mkState B Γ′ body E′ (kont k)
|
2021-12-09 02:57:30 +00:00
|
|
|
|
do-apply-kont (kont halt) a k = part $ do-kont k a
|
|
|
|
|
do-apply-kont {A} {B} {Tω} (kont (kont x)) a k =
|
|
|
|
|
let k′ = chain-kont x k in
|
|
|
|
|
part $ do-kont k′ a
|
|
|
|
|
-- do-apply-kont (kont halt) b (letk Γ C E K) = {! done b !}
|
|
|
|
|
-- do-apply-kont (kont (kont x)) b (letk Γ C E K) = {! !}
|
2021-12-08 18:35:31 +00:00
|
|
|
|
|
|
|
|
|
-- This needs to be a separate function in order to unify B with Tω
|
|
|
|
|
do-apply-halt : ∀ {A Tω} → Value (A ⇒ Tω) → Value A → StepResult Tω
|
|
|
|
|
do-apply-halt {A} {Tω} (clo {Γ} body e) v =
|
2021-12-08 06:33:28 +00:00
|
|
|
|
let Γ′ = Γ , A in
|
|
|
|
|
let E′ = e [ A ∶ v ] in
|
2021-12-08 18:35:31 +00:00
|
|
|
|
part $ mkState Tω Γ′ body E′ halt
|
2021-12-09 02:57:30 +00:00
|
|
|
|
do-apply-halt (kont halt) a = done a
|
|
|
|
|
do-apply-halt (kont (kont k)) a = part $ do-kont k a
|