open_hypergraphs/category/
traits.rs

1// NOTE: in general, objects are taken "owned", but arrows are not.
2// This is because objects are typically owned by the actual result,
3// whereas composition, coproduct etc. creates a *new* result.
4pub trait Arrow: Sized {
5    type Object;
6
7    fn source(&self) -> Self::Object;
8    fn target(&self) -> Self::Object;
9
10    /// the identity morphism on `a`
11    fn identity(a: Self::Object) -> Self;
12
13    /// Compose morphisms in diagrammatic order: `self ; other`
14    ///
15    /// # Errors
16    ///
17    /// Returns None if `self.target() != other.source()`.
18    fn compose(&self, other: &Self) -> Option<Self>;
19}
20
21pub trait Coproduct: Arrow {
22    fn initial_object() -> Self::Object;
23
24    /// Construct the initial arrow `initial_a : 0 → a` from some object `a`
25    fn initial(a: Self::Object) -> Self;
26
27    // Construct the left injection map from two objects
28    fn inj0(a: Self::Object, b: Self::Object) -> Self;
29
30    // Construct the left injection map from two objects
31    fn inj1(a: Self::Object, b: Self::Object) -> Self;
32
33    /// Construct the coproduct of two arrows, or None if they didn't share a codomain.
34    fn coproduct(&self, other: &Self) -> Option<Self>;
35}
36
37pub trait Monoidal: Arrow {
38    /// the monoidal unit object
39    fn unit() -> Self::Object;
40
41    /// `f \otimes g` of two morphisms
42    fn tensor(&self, other: &Self) -> Self;
43}
44
45pub trait SymmetricMonoidal: Monoidal {
46    /// Construct the symmetry `\sigma_{a,b}` from `a` and `b`.
47    fn twist(a: Self::Object, b: Self::Object) -> Self;
48}