-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functor.v
59 lines (43 loc) · 1.56 KB
/
Functor.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(** This file implements the ordinary endofunctors of functional programming. *)
From Tealeaves Require Export
Prelude.
#[local] Generalizable Variables F G A B.
#[local] Notation "F ⇒ G" := (forall A : Type, F A -> G A) (at level 50) : tealeaves_scope.
(** * Endofunctors *)
(******************************************************************************)
Section Functor_operations.
Context
(F : Type -> Type).
Class Fmap : Type :=
fmap : forall (A B : Type) (f : A -> B), F A -> F B.
End Functor_operations.
Section Functor_class.
Context
(F : Type -> Type)
`{Fmap F}.
Class Functor : Prop :=
{ fun_fmap_id : forall (A : Type),
fmap F A A (@id A) = @id (F A);
fun_fmap_fmap : forall (A B C : Type) (f : A -> B) (g : B -> C),
fmap F B C g ∘ fmap F A B f = fmap F A C (g ∘ f);
}.
End Functor_class.
Arguments fmap F%function_scope {Fmap} {A B}%type_scope f%function_scope.
(** ** Natural transformations *)
(******************************************************************************)
Section natural_transformation_class.
Context
`{Functor F}
`{Functor G}.
Class Natural (ϕ : F ⇒ G) :=
{ natural_src : Functor F;
natural_tgt : Functor G;
natural : forall `(f : A -> B),
fmap G f ∘ ϕ A = ϕ B ∘ fmap F f
}.
End natural_transformation_class.
(** * Notations *)
(******************************************************************************)
Module Notations.
Notation "F ⇒ G" := (forall A : Type, F A -> G A) (at level 50) : tealeaves_scope.
End Notations.