| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Base definitions for the left-biased universe-sensitive functor and |
| 5 |
-- monad instances for These. |
| 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 |
|
| 14 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 15 |
|
| 16 |
open import Level |
| 17 |
|
| 18 |
module Data.These.Effectful.Left.Base {a} (A : Set a) (b : Level) where |
| 19 |
|
| 20 |
open import Data.These.Base using (These; this; that; these; map₂) |
| 21 |
open import Effect.Functor using (RawFunctor) |
| 22 |
open import Effect.Applicative using (RawApplicative) |
| 23 |
open import Effect.Monad using (RawMonad) |
| 24 |
open import Function.Base using (_∘_; flip) |
| 25 |
|
| 26 |
Theseₗ : Set (a ⊔ b) → Set (a ⊔ b) |
| 27 |
Theseₗ B = These A B |
| 28 |
|
| 29 |
functor : RawFunctor Theseₗ |
| 30 |
functor = record { _<$>_ = map₂ } |
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- Get access to other monadic functions |
| 34 |
|
| 35 |
module _ {F} (App : RawApplicative {a ⊔ b} {a ⊔ b} F) where |
| 36 |
|
| 37 |
open RawApplicative App |
| 38 |
|
| 39 |
sequenceA : ∀ {A} → Theseₗ (F A) → F (Theseₗ A) |
| 40 |
sequenceA (this a) = pure (this a) |
| 41 |
sequenceA (that b) = that <$> b |
| 42 |
sequenceA (these a b) = these a <$> b |
| 43 |
|
| 44 |
mapA : ∀ {A B} → (A → F B) → Theseₗ A → F (Theseₗ B) |
| 45 |
mapA f = sequenceA ∘ map₂ f |
| 46 |
|
| 47 |
forA : ∀ {A B} → Theseₗ A → (A → F B) → F (Theseₗ B) |
| 48 |
forA = flip mapA |
| 49 |
|
| 50 |
module _ {M} (Mon : RawMonad {a ⊔ b} {a ⊔ b} M) where |
| 51 |
|
| 52 |
private App = RawMonad.rawApplicative Mon |
| 53 |
|
| 54 |
sequenceM : ∀ {A} → Theseₗ (M A) → M (Theseₗ A) |
| 55 |
sequenceM = sequenceA App |
| 56 |
|
| 57 |
mapM : ∀ {A B} → (A → M B) → Theseₗ A → M (Theseₗ B) |
| 58 |
mapM = mapA App |
| 59 |
|
| 60 |
forM : ∀ {A B} → Theseₗ A → (A → M B) → M (Theseₗ B) |
| 61 |
forM = forA App |