Debian Codegraph @

src/Effect/Functor.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Functors
5 ------------------------------------------------------------------------
6
7 -- Note that currently the functor laws are not included here.
8
9 {-# OPTIONS --cubical-compatible --safe #-}
10
11 module Effect.Functor where
12
13 open import Data.Unit.Polymorphic.Base using (⊤)
14 open import Function.Base using (const; flip)
15 open import Level using (Level; suc; _⊔_)
16 open import Relation.Binary.PropositionalEquality.Core using (_≡_)
17
18 private
19 variable
20 ℓ ℓ′ ℓ″ : Level
21 A B X Y : Set ℓ
22
23 record RawFunctor (F : Set ℓ → Set ℓ′) : Set (suc ℓ ⊔ ℓ′) where
24 infixl 4 _<$>_ _<$_
25 infixl 1 _<&>_
26 field
27 _<$>_ : (A → B) → F A → F B
28
29 _<$_ : A → F B → F A
30 x <$ y = const x <$> y
31
32 _<&>_ : F A → (A → B) → F B
33 _<&>_ = flip _<$>_
34
35 ignore : F A → F ⊤
36 ignore = _ <$_
37
38 -- A functor morphism from F₁ to F₂ is an operation op such that
39 -- op (F₁ f x) ≡ F₂ f (op x)
40
41 record Morphism {F₁ : Set ℓ → Set ℓ′} {F₂ : Set ℓ → Set ℓ″}
42 (fun₁ : RawFunctor F₁)
43 (fun₂ : RawFunctor F₂) : Set (suc ℓ ⊔ ℓ′ ⊔ ℓ″) where
44 open RawFunctor
45 field
46 op : F₁ X → F₂ X
47 op-<$> : (f : X → Y) (x : F₁ X) →
48 op (fun₁ ._<$>_ f x) ≡ fun₂ ._<$>_ f (op x)