karpal_higher/
ffunctor.rs1use crate::two_category::TwoCategory;
10
11pub trait FFunctor<C1: TwoCategory, C2: TwoCategory> {
16 fn map_morphism<A: 'static, B: 'static>(f: C1::Morphism<A, B>) -> C2::Morphism<A, B>;
18
19 fn map_two_morphism(alpha: C1::TwoMorphism) -> C2::TwoMorphism;
21}
22
23pub struct IdentityFFunctor<C: TwoCategory>(core::marker::PhantomData<C>);
29
30impl<C: TwoCategory> FFunctor<C, C> for IdentityFFunctor<C> {
31 fn map_morphism<A: 'static, B: 'static>(f: C::Morphism<A, B>) -> C::Morphism<A, B> {
32 f
33 }
34
35 fn map_two_morphism(alpha: C::TwoMorphism) -> C::TwoMorphism {
36 alpha
37 }
38}
39
40pub trait FMonad<C: TwoCategory>: FFunctor<C, C> {
50 fn unit<A: 'static>() -> C::TwoMorphism;
52
53 fn multiply<A: 'static>() -> C::TwoMorphism;
55}
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60 #[cfg(any(feature = "std", feature = "alloc"))]
61 use crate::two_category::Cat;
62
63 #[test]
64 fn identity_ffunctor_preserves_morphism() {
65 struct Marker;
66 impl TwoCategory for Marker {
67 type Morphism<A, B> = ();
68 type TwoMorphism = ();
69 fn id1<A: 'static>() -> Self::Morphism<A, A> {}
70 fn compose1<A: 'static, B: 'static, C: 'static>(
71 _: Self::Morphism<A, B>,
72 _: Self::Morphism<B, C>,
73 ) -> Self::Morphism<A, C> {
74 }
75 fn id2() -> Self::TwoMorphism {}
76 fn compose2_vertical(_: Self::TwoMorphism, _: Self::TwoMorphism) -> Self::TwoMorphism {}
77 }
78 let _unit: () = IdentityFFunctor::<Marker>::map_morphism::<(), ()>(());
79 }
80
81 #[test]
82 fn id_ffunctor_preserves_two_morphism() {
83 struct Marker;
84 impl TwoCategory for Marker {
85 type Morphism<A, B> = ();
86 type TwoMorphism = ();
87 fn id1<A: 'static>() -> Self::Morphism<A, A> {}
88 fn compose1<A: 'static, B: 'static, C: 'static>(
89 _: Self::Morphism<A, B>,
90 _: Self::Morphism<B, C>,
91 ) -> Self::Morphism<A, C> {
92 }
93 fn id2() -> Self::TwoMorphism {}
94 fn compose2_vertical(_: Self::TwoMorphism, _: Self::TwoMorphism) -> Self::TwoMorphism {}
95 }
96 let _unit: () = IdentityFFunctor::<Marker>::map_two_morphism(());
97 }
98}