cek-call-cc/src/Project/Do.agda

33 lines
1.3 KiB
Agda
Raw Normal View History

2021-12-08 18:35:31 +00:00
{-# OPTIONS --allow-unsolved-metas #-}
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 } (L : Letk Tv ) Value Tv State
do-kont {Tv} {} (letk {Tc} Γ C E k) v =
let Γ′ = Γ , Tv in
let E = E [ Tv v ] in
mkState Tc Γ′ C E k
2021-12-08 18:35:31 +00:00
do-apply-kont : {A B } Value (A B) Value A Letk B StepResult
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)
do-apply-kont (kont x) b k = part $ do-kont k {! !}
-- This needs to be a separate function in order to unify B with Tω
do-apply-halt : {A } Value (A ) Value A StepResult
do-apply-halt {A} {} (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 Γ′ body E halt
do-apply-halt (kont halt) b = done b
do-apply-halt (kont (kont x)) b = part $ do-kont x b