Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ New modules
Data.Tree.Rose.Show
```

* `Effect.Monad.Partial` based on domain `Dom` and injection `dom`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There should be more information here (from comments and from PR).


Additions to existing modules
-----------------------------

Expand Down
63 changes: 63 additions & 0 deletions src/Effect/Monad/Partial.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- The partial monad cf. https://1lab.dev/Data.Partial.Base.html
--
-- Modulo proof-relevance, this defines the free pointed DCPO,
-- whereas delay-like monads, as in `Effect.Monad.Partiality`,
-- are aiming to define the free ωCPO.
-- NB. in each case, there are additional 'up to' considerations
-- wrt 'appropriate' setoid equality/quotient/bisimilarity.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably some of the PR information should also be added here).

------------------------------------------------------------------------

{-# OPTIONS --without-K --safe #-}

module Effect.Monad.Partial where

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

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


------------------------------------------------------------------------
-- Object part: type definition

record ↯ (A : Set a) (ℓ : Level) : Set (a ⊔ suc ℓ) where
field
Dom : Set ℓ
dom : Dom → A
Comment thread
jamesmckinna marked this conversation as resolved.

open ↯

------------------------------------------------------------------------
-- Arrow part: Functor, Applicative, Monad component definition

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

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

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

------------------------------------------------------------------------
-- Specific constructions

never : ↯ A ℓ
never {ℓ = ℓ} .Dom = ⊥ {ℓ = ℓ}
never .dom = ⊥-elim

always : A → ↯ A ℓ
always {ℓ = ℓ} a .Dom = ⊤ {ℓ = ℓ}
always a .dom _ = a

Loading