Skip to content
Draft
Changes from all 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
51 changes: 51 additions & 0 deletions src/Effect/Monad/Partial.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- The partial monad
------------------------------------------------------------------------

{-# OPTIONS --cubical-compatible --safe #-}

module Effect.Monad.Partial where

open import Level using (Level; suc; zero;_⊔_)
open import Data.Product using (_×_; Σ; Σ-syntax; _,_)
open import Data.Empty using (⊥-elim; ⊥)
open import Data.Unit using (⊤)

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

------------------------------------------------------------------------
-- The partial monad

record ↯ (A : Set a) (ℓ : Level) : Set (a ⊔ suc ℓ) where
field
Dom : Set ℓ
elt : Dom → A

open ↯

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↓)
Comment on lines +39 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.
What's the unicode name for the down-lightning-bolt symbol, given that this is going to be in frequent use, if deployed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the unicode : U+21AF

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an Emacs agda-input-mode version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes (sorry for the delay), it's \dz.