This commit is contained in:
Leon Vatthauer 2023-12-07 18:54:15 +01:00
parent 59f60810e7
commit 7ec344dfeb
Signed by: leonv
SSH key fingerprint: SHA256:G4+ddwoZmhLPRB1agvXzZMXIzkVJ36dUYZXf5NxT+u8

View file

@ -109,16 +109,16 @@ module Monad.Instance.K.Instance.Delay {c } where
now-inj {A} {x} {y} (↓≈ ab (now↓ xa) (now↓ yb)) = -trans A xa (-trans A ab (-sym A yb)) now-inj {A} {x} {y} (↓≈ ab (now↓ xa) (now↓ yb)) = -trans A xa (-trans A ab (-sym A yb))
delayFun : ∀ {A B : Setoid c (c ⊔ )} → A ⟶ B → delaySetoid A ⟶ delaySetoid B delayFun : ∀ {A B : Setoid c (c ⊔ )} → A ⟶ B → delaySetoid A ⟶ delaySetoid B
delayFun {A} {B} f = record { _⟨$⟩_ = app ; cong = cong' } delayFun {A} {B} f = record { _⟨$⟩_ = liftF ; cong = cong' }
where where
app : Delay (Setoid.Carrier A) → Delay (Setoid.Carrier B) liftF : Delay (Setoid.Carrier A) → Delay (Setoid.Carrier B)
app (now x) = now (f ⟨$⟩ x) liftF (now x) = now (f ⟨$⟩ x)
app (later x) = later (♯ app (♭ x)) liftF (later x) = later (♯ liftF (♭ x))
-- TODO a variant of this should be useful outside -- TODO a variant of this should be useful outside
↓-cong : ∀ {x : Delay (Setoid.Carrier A)} {b : Setoid.Carrier A} → _↓_ {A} x b → _↓_ {B} (app x) (f ⟨$⟩ b) ↓-cong : ∀ {x : Delay (Setoid.Carrier A)} {b : Setoid.Carrier A} → _↓_ {A} x b → _↓_ {B} (liftF x) (f ⟨$⟩ b)
↓-cong {now x} {b} (now↓ xy) = now↓ (cong f xy) ↓-cong {now x} {b} (now↓ xy) = now↓ (cong f xy)
↓-cong {later x} {b} (later↓ x↓b) = later↓ (↓-cong x↓b) ↓-cong {later x} {b} (later↓ x↓b) = later↓ (↓-cong x↓b)
cong' : ∀ {x y : Delay (Setoid.Carrier A)} → A [ x ≈ y ] → B [ app x ≈ app y ] cong' : ∀ {x y : Delay (Setoid.Carrier A)} → A [ x ≈ y ] → B [ liftF x ≈ liftF y ]
cong' {now x} {now y} (↓≈ ab (now↓ xa) (now↓ yb)) = now-cong (cong f (-trans A xa (-trans A ab (-sym A yb)))) cong' {now x} {now y} (↓≈ ab (now↓ xa) (now↓ yb)) = now-cong (cong f (-trans A xa (-trans A ab (-sym A yb))))
cong' {now x} {later y} (↓≈ ab (now↓ xa) (later↓ y↓b)) = ↓≈ (cong f (-trans A xa ab)) (now↓ (-refl B)) (later↓ (↓-cong y↓b)) cong' {now x} {later y} (↓≈ ab (now↓ xa) (later↓ y↓b)) = ↓≈ (cong f (-trans A xa ab)) (now↓ (-refl B)) (later↓ (↓-cong y↓b))
cong' {later x} {now y} (↓≈ ab (later↓ x↓a) (now↓ yb)) = ↓≈ (cong f (-trans A ab (-sym A yb))) (later↓ (↓-cong x↓a)) (now↓ (-refl B)) cong' {later x} {now y} (↓≈ ab (later↓ x↓a) (now↓ yb)) = ↓≈ (cong f (-trans A ab (-sym A yb))) (later↓ (↓-cong x↓a)) (now↓ (-refl B))
@ -151,6 +151,20 @@ module Monad.Instance.K.Instance.Delay {c } where
delayFun-id {A} {later x} {later y} (↓≈ ab (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ delayFun-id (↓≈ ab x↓a y↓b)) delayFun-id {A} {later x} {later y} (↓≈ ab (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ delayFun-id (↓≈ ab x↓a y↓b))
delayFun-id {A} {later x} {later y} (later≈ x≈y) = later≈ (♯ delayFun-id (♭ x≈y)) delayFun-id {A} {later x} {later y} (later≈ x≈y) = later≈ (♯ delayFun-id (♭ x≈y))
delayFun-comp : ∀ {A B C : Setoid c (c ⊔ )} {f : A ⟶ B} {g : B ⟶ C} → delayFun (g ∘ f) ≋ (delayFun g ∘ delayFun f)
delayFun-comp {A} {B} {C} {f} {g} {now x} {now y} (↓≈ ab (now↓ xa) (now↓ yb)) = now-cong (cong g (cong f (-trans A xa (-trans A ab (-sym A yb)))))
delayFun-comp {A} {B} {C} {f} {g} {now x} {later y} (↓≈ ab (now↓ xa) (later↓ y↓b)) = ↓≈ (cong g (cong f (-trans A xa ab))) (now↓ (-refl C)) (later↓ (delayFun↓ g (delayFun↓ f y↓b)))
delayFun-comp {A} {B} {C} {f} {g} {later x} {now y} (↓≈ ab (later↓ x↓a) (now↓ yb)) = ↓≈ (cong g (cong f (-trans A ab (-sym A yb)))) (later↓ (delayFun↓ (g ∘ f) x↓a)) (now↓ (-refl C))
delayFun-comp {A} {B} {C} {f} {g} {later x} {later y} (↓≈ ab (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ delayFun-comp (↓≈ ab x↓a y↓b))
delayFun-comp {A} {B} {C} {f} {g} {later x} {later y} (later≈ x≈y) = later≈ (♯ delayFun-comp (♭ x≈y))
delayFun-resp-≈ : ∀ {A B : Setoid c (c ⊔ )} {f g : A ⟶ B} → f ≋ g → delayFun f ≋ delayFun g
delayFun-resp-≈ {A} {B} {f} {g} f≋g {now x} {now y} x≈y = now-cong (f≋g (now-inj x≈y))
delayFun-resp-≈ {A} {B} {f} {g} f≋g {now x} {later y} (↓≈ ab (now↓ xa) (later↓ y↓b)) = ↓≈ (f≋g (-trans A xa ab)) (now↓ (-refl B)) (later↓ (delayFun↓ g y↓b))
delayFun-resp-≈ {A} {B} {f} {g} f≋g {later x} {now y} (↓≈ ab (later↓ x↓a) (now↓ yb)) = ↓≈ (f≋g (-trans A ab (-sym A yb))) (later↓ (delayFun↓ f x↓a)) (now↓ (-refl B))
delayFun-resp-≈ {A} {B} {f} {g} f≋g {later x} {later y} (↓≈ ab (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ delayFun-resp-≈ f≋g (↓≈ ab x↓a y↓b))
delayFun-resp-≈ {A} {B} {f} {g} f≋g {later x} {later y} (later≈ x≈y) = later≈ (♯ delayFun-resp-≈ f≋g (♭ x≈y))
η : ∀ (A : Setoid c (c ⊔ )) → A ⟶ delaySetoid A η : ∀ (A : Setoid c (c ⊔ )) → A ⟶ delaySetoid A
η A = record { _⟨$⟩_ = now ; cong = id λ xy → now-cong xy } η A = record { _⟨$⟩_ = now ; cong = id λ xy → now-cong xy }
@ -181,22 +195,29 @@ module Monad.Instance.K.Instance.Delay {c } where
μ-natural : ∀ {A B : Setoid c (c ⊔ )} (f : A ⟶ B) → (μ B ∘ delayFun (delayFun f)) ≋ (delayFun f ∘ μ A) μ-natural : ∀ {A B : Setoid c (c ⊔ )} (f : A ⟶ B) → (μ B ∘ delayFun (delayFun f)) ≋ (delayFun f ∘ μ A)
μ-natural {A} {B} f {now x} {now y} nx≈ny = cong (delayFun f) (now-inj nx≈ny) μ-natural {A} {B} f {now x} {now y} nx≈ny = cong (delayFun f) (now-inj nx≈ny)
μ-natural {A} {B} f {now x} {later y} (↓≈ a≈b (now↓ x≈a) (later↓ y↓b)) = later-eq (later≈ (♯ cong (delayFun f) (≈-sym (μ↓ (∼↓ (≈-trans (≈-sym a≈b) (≈-sym x≈a)) y↓b))))) μ-natural {A} {B} f {now x} {later y} (↓≈ a≈b (now↓ x≈a) (later↓ y↓b)) = later-eq (later≈ (♯ cong (delayFun f) (≈-sym (μ↓ (∼↓ (≈-trans (≈-sym a≈b) (≈-sym x≈a)) y↓b)))))
μ-natural {A} {B} f {later x} {now y} (↓≈ ab x↓a y↓b) = {! !} μ-natural {A} {B} f {later x} {now y} (↓≈ a≈b (later↓ x↓a) (now↓ y≈b)) = ≈-sym (later-eq (later≈ (♯ ≈-sym (μ↓ (∼↓ (cong (delayFun f) (≈-trans a≈b (≈-sym y≈b))) (delayFun↓ (delayFun f) x↓a))))))
μ-natural {A} {B} f {later x} {later y} (↓≈ ab x↓a y↓b) = {! !} μ-natural {A} {B} f {later x} {later y} (↓≈ a≈b (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ μ-natural f (↓≈ a≈b x↓a y↓b))
μ-natural {A} {B} f {later x} {later y} (later≈ x≈y) = later≈ (♯ μ-natural f (♭ x≈y)) μ-natural {A} {B} f {later x} {later y} (later≈ x≈y) = later≈ (♯ μ-natural f (♭ x≈y))
μ-assoc : ∀ {A : Setoid c (c ⊔ )} → (μ A ∘ (delayFun (μ A))) ≋ (μ A ∘ μ (delaySetoid A))
μ-assoc {A} {now x} {now y} (↓≈ a≈b (now↓ x≈a) (now↓ y≈b)) = cong (μ A) (≈-trans x≈a (≈-trans a≈b (≈-sym y≈b)))
μ-assoc {A} {now x} {later y} (↓≈ a≈b (now↓ x≈a) (later↓ y↓b)) = later-eq (later≈ (♯ cong (μ A) (≈-sym (μ↓ (∼↓ (≈-sym (≈-trans x≈a a≈b)) y↓b)))))
μ-assoc {A} {later x} {now y} (↓≈ a≈b (later↓ x↓a) (now↓ y≈b)) = ≈-sym (later-eq (later≈ (♯ {! !}))) -- μ (now y) ≈ y ≈ lift (μ A) (♭ x) --> now y ↓
μ-assoc {A} {later x} {later y} (↓≈ a≈b (later↓ x↓a) (later↓ y↓b)) = later≈ (♯ μ-assoc (↓≈ a≈b x↓a y↓b))
μ-assoc {A} {later x} {later y} (later≈ x≈y) = later≈ (♯ μ-assoc (♭ x≈y))
delayMonad : Monad (Setoids c (c ⊔ )) delayMonad : Monad (Setoids c (c ⊔ ))
delayMonad = record delayMonad = record
{ F = record { F = record
{ F₀ = delaySetoid { F₀ = delaySetoid
; F₁ = delayFun ; F₁ = delayFun
; identity = delayFun-id ; identity = delayFun-id
; homomorphism = {! !} ; homomorphism = delayFun-comp
; F-resp-≈ = {! !} ; F-resp-≈ = delayFun-resp-≈
} }
; η = ntHelper (record { η = η ; commute = η-natural }) ; η = ntHelper (record { η = η ; commute = η-natural })
; μ = ntHelper (record { η = μ ; commute = μ-natural }) ; μ = ntHelper (record { η = μ ; commute = μ-natural })
; assoc = {! !} ; assoc = μ-assoc
; sym-assoc = {! !} ; sym-assoc = {! !}
; identityˡ = {! !} ; identityˡ = {! !}
; identityʳ = {! !} ; identityʳ = {! !}