Debian Codegraph @

src/Data/These/Effectful/Right.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Right-biased universe-sensitive functor and monad instances for These.
5 ------------------------------------------------------------------------
6
7 -- To minimize the universe level of the RawFunctor, we require that
8 -- elements of B are "lifted" to a copy of B at a higher universe level
9 -- (a ⊔ b).
10 -- See the Data.Product.Effectful.Examples for how this is done in a
11 -- Product-based similar setting.
12
13 -- This functor can be understood as a notion of computation which can
14 -- either fail (that), succeed (this) or accumulate warnings whilst
15 -- delivering a successful computation (these).
16
17 -- It is a good alternative to Data.Product.Effectful when the notion
18 -- of warnings does not have a neutral element (e.g. List⁺).
19
20 {-# OPTIONS --cubical-compatible --safe #-}
21
22 open import Level using (Level; _⊔_)
23 open import Algebra.Bundles using (Semigroup)
24
25 module Data.These.Effectful.Right (a : Level) {c ℓ} (W : Semigroup c ℓ) where
26
27 open import Data.These.Base using (These; this; that; these; map₁; map₂; map)
28 open import Effect.Applicative using (RawApplicative)
29 open import Effect.Monad using (RawMonad)
30
31 open Semigroup W
32 open import Data.These.Effectful.Right.Base a Carrier public
33
34 module _ {a b} {A : Set a} {B : Set b} where
35
36 applicative : RawApplicative Theseᵣ
37 applicative = record
38 { rawFunctor = functor
39 ; pure = this
40 ; _<*>_ = ap
41 } where
42
43 ap : ∀ {A B}→ Theseᵣ (A → B) → Theseᵣ A → Theseᵣ B
44 ap (this f) t = map₁ f t
45 ap (that w) t = that w
46 ap (these f w) t = map f (w ∙_) t
47
48 monad : RawMonad Theseᵣ
49 monad = record
50 { rawApplicative = applicative
51 ; _>>=_ = bind
52 } where
53
54 bind : ∀ {A B} → Theseᵣ A → (A → Theseᵣ B) → Theseᵣ B
55 bind (this t) f = f t
56 bind (that w) f = that w
57 bind (these t w) f = map₂ (w ∙_) (f t)