Skip to content
Snippets Groups Projects
Commit 58322c81 authored by Eric Giovannini's avatar Eric Giovannini
Browse files

New defintion of Dyn; changes to EP pairs

parent 9cbd06d9
No related branches found
No related tags found
No related merge requests found
{-# OPTIONS --cubical --rewriting --guarded #-} {-# OPTIONS --cubical --rewriting --guarded #-}
-- to allow opening this module in other files while there are still holes
{-# OPTIONS --allow-unsolved-metas #-}
open import Later open import Later
module ErrorDomains(k : Clock) where module ErrorDomains(k : Clock) where
...@@ -65,6 +68,7 @@ mapL' : (A -> B) -> ▹ (L℧ A -> L℧ B) -> L℧ A -> L℧ B ...@@ -65,6 +68,7 @@ mapL' : (A -> B) -> ▹ (L℧ A -> L℧ B) -> L℧ A -> L℧ B
mapL' f map_rec (η x) = η (f x) mapL' f map_rec (η x) = η (f x)
mapL' f map_rec ℧ = ℧ mapL' f map_rec ℧ = ℧
mapL' f map_rec (θ l_la) = θ (map_rec ⊛ l_la) mapL' f map_rec (θ l_la) = θ (map_rec ⊛ l_la)
-- mapL' f map_rec (θ-next x i) = θ-next {!!} {!!}
mapL : (A -> B) -> L℧ A -> L℧ B mapL : (A -> B) -> L℧ A -> L℧ B
mapL f = fix (mapL' f) mapL f = fix (mapL' f)
...@@ -161,7 +165,7 @@ map-comp : {A B C : Set} (g : B -> C) (f : A -> B) (x : ▹_,_ k _) -> ...@@ -161,7 +165,7 @@ map-comp : {A B C : Set} (g : B -> C) (f : A -> B) (x : ▹_,_ k _) ->
map-comp g f x = -- could just say refl for the whole thing map-comp g f x = -- could just say refl for the whole thing
map▹ g (map▹ f x) ≡⟨ refl ⟩ map▹ g (map▹ f x) ≡⟨ refl ⟩
(λ α -> g ((map▹ f x) α)) ≡⟨ refl ⟩ (λ α -> g ((map▹ f x) α)) ≡⟨ refl ⟩
(λ α -> g ((λ β -> f (x β)) α)) ≡⟨ refl ⟩ -- (λ α -> g ((λ β -> f (x β)) α)) ≡⟨ refl ⟩
(λ α -> g (f (x α))) ≡⟨ refl ⟩ (λ α -> g (f (x α))) ≡⟨ refl ⟩
map▹ (g ∘ f) x ∎ map▹ (g ∘ f) x ∎
...@@ -226,26 +230,49 @@ monad-assoc = fix lem ...@@ -226,26 +230,49 @@ monad-assoc = fix lem
-- bind (θ ( (λ la -> bind la f) <$> x)) g ≡⟨ {!!} ⟩ -- bind (θ ( (λ la -> bind la f) <$> x)) g ≡⟨ {!!} ⟩
--------------------------------------------------------------------------
-- 1. Define denotational semantics for gradual STLC and show soundness of term precision
-- 1a. Define interpretation of terms of gradual CBV cast calculus (STLC + casts)
-- i) Semantic domains
-- ii) Term syntax (intrinsically typed, de Bruijn)
-- iii) Denotation function
-- 1b. Soundness of term precision with equational theory only (no ordering)
-- The language supports Dyn, CBV functions, nat
-- Dyn as a predomain data Dyn' (D : ▹ Type) : Type where
data Dyn' (D : ▹ Type) : Type where
nat : ℕ -> Dyn' D nat : ℕ -> Dyn' D
arr : (▸ D -> L℧ (▸ D)) -> Dyn' D arr : ▸ (λ t → D t -> L℧ (D t)) -> Dyn' D
Dyn : Type Dyn : Type
Dyn = fix Dyn' Dyn = fix Dyn'
-- Embedding-projection pairs -- Embedding-projection pairs
record EP (A B : Set) : Set where record EP (A B : Set) : Set where
field field
emb : A -> B emb : A -> B
proj : B -> L℧ A proj : B -> L℧ A
retract :
proj ∘ emb ≡ ret
-- E-P Pair for a type with itself
EP-id : (A : Type) -> EP A A
EP-id A = record {
emb = id;
proj = ret }
-- Composing EP pairs
EP-comp : {A B C : Type} -> EP A B -> EP B C -> EP A C
EP-comp epAB epBC = record {
emb = λ a -> emb epBC (emb epAB a) ;
proj = λ c -> bind (proj epBC c) (proj epAB) }
where open EP
-- E-P Pair for nat -- E-P Pair for nat
...@@ -268,66 +295,52 @@ retraction-nat n = ...@@ -268,66 +295,52 @@ retraction-nat n =
EP-nat : EP ℕ Dyn EP-nat : EP ℕ Dyn
EP-nat = record { EP-nat = record {
emb = e-nat; emb = e-nat;
proj = p-nat; proj = p-nat }
retract = funExt retraction-nat }
-- E-P Pair for function types
e-fun : (Dyn -> L℧ Dyn) -> Dyn -- E-P Pair for functions Dyn to L℧ Dyn
e-fun f = transport
(sym (fix-eq Dyn'))
(arr λ (x : ▹ Dyn) →
θ (λ t -> mapL next (f (x t))))
apply : Tick k -> ▹ Dyn -> Dyn e-fun : (Dyn -> L℧ Dyn) -> Dyn
apply t l_dyn = l_dyn t e-fun f = transport (sym (fix-eq Dyn'))
(arr (next f))
p-fun' : Dyn' (next Dyn) -> L℧ (Dyn -> L℧ Dyn) p-fun' : Dyn' (next Dyn) -> L℧ (Dyn -> L℧ Dyn)
p-fun' (nat n) = ℧ p-fun' (nat x) = ℧
p-fun' (arr f) = ret λ d -> p-fun' (arr x) = θ (ret <$> x) -- could also define using tick
θ (λ t →
mapL (apply t) (f (next d))
-- doesn't work:
-- mapL (\ (l_dyn : ▹ Dyn) -> l_dyn t) (f (next d))
)
-- f : ▸ next Dyn → L℧ (▸ next Dyn)
-- which is equal to
-- ▹ Dyn -> L℧ (▹ Dyn)
p-fun : Dyn -> L℧ (Dyn -> L℧ Dyn) p-fun : Dyn -> L℧ (Dyn -> L℧ Dyn)
p-fun d = p-fun' (transport (fix-eq Dyn') d) p-fun d = p-fun' (transport (fix-eq Dyn') d)
theta-lem : (t : Tick k) (la : L℧ A) -> fun-retract : (f : (Dyn -> L℧ Dyn)) ->
θ (λ t -> la) ≡ θ (next la) p-fun (e-fun f) ≡ θ (next (ret f))
theta-lem t la = refl fun-retract f =
p-fun' (transport (fix-eq Dyn') (e-fun f))
≡⟨ refl ⟩
retraction-fun : (h : Dyn -> L℧ Dyn) -> p-fun' (transport (fix-eq Dyn') (transport (sym (fix-eq Dyn')) (arr (next f))))
p-fun (e-fun h) ≡ {!!} ≡⟨ (λ i → p-fun' (transportTransport⁻ (fix-eq Dyn') (arr (next f)) i)) ⟩
retraction-fun h = {!!} p-fun' (arr (next f)) ≡⟨ refl ⟩
θ (ret <$> next f) ≡⟨ refl ⟩
θ (next (ret f)) ∎
EP-fun : EP (Dyn -> L℧ Dyn) Dyn EP-fun : EP (Dyn -> L℧ Dyn) Dyn
EP-fun = record { EP-fun = record {
emb = e-fun; emb = e-fun;
proj = p-fun; proj = p-fun }
retract = {!!} }
-- Lifting retractions to functions -- Lifting retractions to functions
module LiftRetraction module LiftRetraction
(A A' B B' : Set) {A A' B B' : Set}
(epAA' : EP A A') (epAA' : EP A A')
(epBB' : EP B B') where (epBB' : EP B B') where
e-lift : e-lift :
(A → L℧ B) → (A' → L℧ B') (A → L℧ B) → (A' → L℧ B')
e-lift h a' = e-lift f a' =
bind (EP.proj {!!} a') λ a -> mapL (EP.emb {!!}) (h a) bind (EP.proj epAA' a') λ a -> mapL (EP.emb epBB') (f a)
-- or equivalently: -- or equivalently:
-- mapL (EP.emb epBB') (bind (EP.proj epAA' a') h) -- mapL (EP.emb epBB') (bind (EP.proj epAA' a') h)
...@@ -338,6 +351,19 @@ module LiftRetraction ...@@ -338,6 +351,19 @@ module LiftRetraction
EP-lift : {A A' B B' : Set} ->
EP A A' ->
EP B B' ->
EP (A -> L℧ B) (A' -> L℧ B')
EP-lift epAA' epBB' = record {
emb = e-lift;
proj = p-lift }
where open LiftRetraction epAA' epBB'
{- {-
...@@ -348,16 +374,6 @@ L℧ X = record { X = L℧X ; ℧ = ℧ ; ℧⊥ = {!!} ; θ = record { f = θ ...@@ -348,16 +374,6 @@ L℧ X = record { X = L℧X ; ℧ = ℧ ; ℧⊥ = {!!} ; θ = record { f = θ
L℧X = L℧₀ (X .fst) , {!!} L℧X = L℧₀ (X .fst) , {!!}
-} -}
-- Plan:
-- 1. Define denotational semantics for gradual STLC and show soundness of term precision
-- 1a. Define interpretation of terms of gradual CBV cast calculus (STLC + casts)
-- i) Semantic domains
-- ii) Term syntax (intrinsically typed, de Bruijn)
-- iii) Denotation function
-- 1b. Soundness of term precision with equational theory only (no ordering)
-- The language supports Dyn, CBV functions, nat
-- | TODO: -- | TODO:
-- | 1. monotone monad structure -- | 1. monotone monad structure
-- | 2. strict functions -- | 2. strict functions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment