fp_library/types/
disjunctive.rs1#[fp_macros::document_module]
17mod inner {
18 use {
19 crate::classes::*,
20 fp_macros::*,
21 };
22
23 #[document_examples]
29 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41 #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
42 pub struct Disjunctive<A>(
43 pub A,
45 );
46
47 #[document_type_parameters("The Heyting algebra type.")]
48 impl<A: HeytingAlgebra> Semigroup for Disjunctive<A> {
49 #[document_signature]
51 #[document_parameters("The first disjunctive value.", "The second disjunctive value.")]
53 #[document_returns("The disjunction wrapped in `Disjunctive`.")]
55 #[document_examples]
56 fn append(
66 a: Self,
67 b: Self,
68 ) -> Self {
69 Disjunctive(A::disjoin(a.0, b.0))
70 }
71 }
72
73 #[document_type_parameters("The Heyting algebra type.")]
74 impl<A: HeytingAlgebra> Monoid for Disjunctive<A> {
75 #[document_signature]
77 #[document_returns("The bottom element wrapped in `Disjunctive`.")]
79 #[document_examples]
80 fn empty() -> Self {
90 Disjunctive(A::false_value())
91 }
92 }
93}
94
95pub use inner::*;
96
97#[cfg(test)]
98mod tests {
99 use {
100 super::*,
101 crate::functions::*,
102 quickcheck_macros::quickcheck,
103 };
104
105 #[quickcheck]
106 fn semigroup_associativity(
107 a: bool,
108 b: bool,
109 c: bool,
110 ) -> bool {
111 let x = Disjunctive(a);
112 let y = Disjunctive(b);
113 let z = Disjunctive(c);
114 append(x, append(y, z)) == append(append(x, y), z)
115 }
116
117 #[quickcheck]
118 fn monoid_left_identity(a: bool) -> bool {
119 let x = Disjunctive(a);
120 append(empty::<Disjunctive<bool>>(), x) == x
121 }
122
123 #[quickcheck]
124 fn monoid_right_identity(a: bool) -> bool {
125 let x = Disjunctive(a);
126 append(x, empty::<Disjunctive<bool>>()) == x
127 }
128}