Debian Codegraph @

src/Effect/Monad/Identity.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- An effectful view of the identity function
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Effect.Monad.Identity where
10
11 open import Effect.Functor using (RawFunctor)
12 open import Effect.Applicative using (RawApplicative)
13 open import Effect.Monad using (RawMonad; module Join)
14 open import Effect.Comonad using (RawComonad)
15 open import Function.Base using (id; _∘′_; _|>′_; _$′_; flip)
16 open import Level using (Level)
17
18 private
19 variable
20 a : Level
21 A : Set a
22
23 record Identity (A : Set a) : Set a where
24 constructor mkIdentity
25 field runIdentity : A
26 open Identity public
27
28 functor : RawFunctor {a} Identity
29 functor = record
30 { _<$>_ = λ f a → mkIdentity (f (runIdentity a))
31 }
32
33 applicative : RawApplicative {a} Identity
34 applicative = record
35 { rawFunctor = functor
36 ; pure = mkIdentity
37 ; _<*>_ = λ f a → mkIdentity (runIdentity f $′ runIdentity a)
38 }
39
40 monad : RawMonad {a} Identity
41 monad = record
42 { rawApplicative = applicative
43 ; _>>=_ = _|>′_ ∘′ runIdentity
44 }
45
46 comonad : RawComonad {a} Identity
47 comonad = record
48 { extract = runIdentity
49 ; extend = λ f a → mkIdentity (f a)
50 }
51
52 join : Identity (Identity A) → Identity A
53 join = Join.join monad