Skip to content

[add] partial elements in Effect.Monad.Partial module #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Effect/Monad/Partial.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Effect.Monad.Partial where

open import Level

open import Data.Product
open import Data.Empty
open import Data.Unit

-- The type of partial elements
record ↯ {ℓ} (A : Set ℓ) (ℓ' : Level) : Set (ℓ ⊔ suc ℓ') where
field
Dom : Set ℓ'
elt : Dom → A

open ↯

private variable
ℓ ℓ' : Level
A B : Set ℓ


--
never : ↯ A zero
never .Dom = ⊥
never .elt = ⊥-elim

always : A → ↯ A zero
always a .Dom = ⊤
always a .elt _ = a

-----------------------
↯-bind : ↯ A ℓ → (A → ↯ B ℓ') → ↯ B (ℓ ⊔ ℓ')
↯-bind a↯ f .Dom = Σ[ a↓ ∈ a↯ .Dom ] f (a↯ .elt a↓) .Dom
↯-bind a↯ f .elt (a↓ , fa↓) = f (a↯ .elt a↓) .elt fa↓

-----------------------
↯-map : (A → B) → ↯ A ℓ → ↯ B ℓ
↯-map f a↯ .Dom = a↯ .Dom
↯-map f a↯ .elt d = f (a↯ .elt d)

-----------------------
↯-ap : ↯ (A → B) ℓ → ↯ A ℓ' → ↯ B (ℓ ⊔ ℓ')
↯-ap a→b↯ a↯ .Dom = a→b↯ .Dom × a↯ .Dom
↯-ap a→b↯ a↯ .elt (f↓ , a↓) = a→b↯ .elt f↓ (a↯ .elt a↓)