Work on maybe

This commit is contained in:
Leon Vatthauer 2023-12-01 15:34:21 +01:00
parent 7be2f41196
commit b63d5455be
Signed by: leonv
SSH key fingerprint: SHA256:G4+ddwoZmhLPRB1agvXzZMXIzkVJ36dUYZXf5NxT+u8

View file

@ -25,8 +25,8 @@ open import Function.Base using (id)
--> -->
```agda ```agda
module Monad.Instance.K.Instance.Maybe {o e} (ambient : Ambient o e) where -- TODO arguments c here!
open Ambient ambient using () module Monad.Instance.K.Instance.Maybe {o e} where
``` ```
# The Maybe Monad as instance of K # The Maybe Monad as instance of K
@ -85,12 +85,18 @@ module _ {c : Level} where
maybeFun-comp : ∀ {A B C : Setoid c } (f : A ⟶ B) (g : B ⟶ C) → maybeFun (g ∘ f) ≋ ((maybeFun g) ∘ (maybeFun f)) maybeFun-comp : ∀ {A B C : Setoid c } (f : A ⟶ B) (g : B ⟶ C) → maybeFun (g ∘ f) ≋ ((maybeFun g) ∘ (maybeFun f))
maybeFun-comp {A} {B} {C} f g {nothing} {nothing} i≈j = i≈j maybeFun-comp {A} {B} {C} f g {nothing} {nothing} i≈j = i≈j
maybeFun-comp {A} {B} {C} f g {just i} {just j} i≈j = cong g (cong f i≈j) maybeFun-comp {A} {B} {C} f g {just _} {just _} i≈j = cong g (cong f i≈j)
maybeFun-resp-≈ : ∀ {A B : Setoid c } {f g : A ⟶ B} → f ≋ g → maybeFun f ≋ maybeFun g
maybeFun-resp-≈ {A} {B} {f} {g} f≈g {nothing} {nothing} i≈j = i≈j
maybeFun-resp-≈ {A} {B} {f} {g} f≈g {just _} {just _} i≈j = f≈g i≈j
η : ∀ (A : Setoid c ) → A ⟶ maybeSetoid A η : ∀ (A : Setoid c ) → A ⟶ maybeSetoid A
η A = record { _⟨$⟩_ = just ; cong = id } η A = record { _⟨$⟩_ = just ; cong = id }
η-natural : ∀ {A B : Setoid c } (f : A ⟶ B) → (η B ∘ f) ≋ (maybeFun f ∘ η A)
η-natural {A} {B} f {i} {j} i≈j = cong f i≈j
μ : ∀ (A : Setoid c ) → maybeSetoid (maybeSetoid A) ⟶ maybeSetoid A μ : ∀ (A : Setoid c ) → maybeSetoid (maybeSetoid A) ⟶ maybeSetoid A
μ A = record { _⟨$⟩_ = app ; cong = λ {i} {j} → cong' i j } μ A = record { _⟨$⟩_ = app ; cong = λ {i} {j} → cong' i j }
where where
@ -101,6 +107,10 @@ module _ {c : Level} where
cong' nothing nothing i≈j = i≈j cong' nothing nothing i≈j = i≈j
cong' (just i) (just j) i≈j = i≈j cong' (just i) (just j) i≈j = i≈j
μ-natural : ∀ {A B : Setoid c } (f : A ⟶ B) → (μ B ∘ maybeFun (maybeFun f)) ≋ (maybeFun f ∘ μ A)
μ-natural {A} {B} f {nothing} {nothing} i≈j = i≈j
μ-natural {A} {B} f {just i} {just j} i≈j = cong (maybeFun f) {i} {j} i≈j
maybeMonad : Monad (Setoids c ) maybeMonad : Monad (Setoids c )
maybeMonad = record maybeMonad = record
{ F = record { F = record
@ -108,15 +118,15 @@ module _ {c : Level} where
; F₁ = maybeFun ; F₁ = maybeFun
; identity = λ {A} {x} {y} → maybeFun-id {A = A} {x} {y} ; identity = λ {A} {x} {y} → maybeFun-id {A = A} {x} {y}
; homomorphism = λ {A} {B} {C} {f} {g} {i} {j} → maybeFun-comp {A} {B} {C} f g {i} {j} ; homomorphism = λ {A} {B} {C} {f} {g} {i} {j} → maybeFun-comp {A} {B} {C} f g {i} {j}
; F-resp-≈ = {! !} ; F-resp-≈ = maybeFun-resp-≈
} }
; η = ntHelper (record ; η = ntHelper (record
{ η = η { η = η
; commute = {! !} ; commute = η-natural
}) })
; μ = ntHelper (record ; μ = ntHelper (record
{ η = μ { η = μ
; commute = {! !} ; commute = μ-natural
}) })
; assoc = {! !} ; assoc = {! !}
; sym-assoc = {! !} ; sym-assoc = {! !}