| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Comonads |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- Note that currently the monad laws are not included here. |
| 8 |
|
| 9 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 10 |
|
| 11 |
module Effect.Comonad where |
| 12 |
|
| 13 |
open import Level using (Level; suc) |
| 14 |
open import Function.Base using (id; _∘′_; flip) |
| 15 |
|
| 16 |
private |
| 17 |
variable |
| 18 |
a b c f : Level |
| 19 |
A : Set a |
| 20 |
B : Set b |
| 21 |
C : Set c |
| 22 |
|
| 23 |
record RawComonad (W : Set f → Set f) : Set (suc f) where |
| 24 |
|
| 25 |
infixl 1 _=>>_ _=>=_ |
| 26 |
infixr 1 _<<=_ _=<=_ |
| 27 |
|
| 28 |
field |
| 29 |
extract : W A → A |
| 30 |
extend : (W A → B) → (W A → W B) |
| 31 |
|
| 32 |
duplicate : W A → W (W A) |
| 33 |
duplicate = extend id |
| 34 |
|
| 35 |
liftW : (A → B) → W A → W B |
| 36 |
liftW f = extend (f ∘′ extract) |
| 37 |
|
| 38 |
_=>>_ : W A → (W A → B) → W B |
| 39 |
_=>>_ = flip extend |
| 40 |
|
| 41 |
_=>=_ : (W A → B) → (W B → C) → W A → C |
| 42 |
f =>= g = g ∘′ extend f |
| 43 |
|
| 44 |
_<<=_ : (W A → B) → W A → W B |
| 45 |
_<<=_ = extend |
| 46 |
|
| 47 |
_=<=_ : (W B → C) → (W A → B) → W A → C |
| 48 |
_=<=_ = flip _=>=_ |