summaryrefslogtreecommitdiff
path: root/receme/src/ralgebra.rs
diff options
context:
space:
mode:
Diffstat (limited to 'receme/src/ralgebra.rs')
-rw-r--r--receme/src/ralgebra.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/receme/src/ralgebra.rs b/receme/src/ralgebra.rs
new file mode 100644
index 0000000..989089e
--- /dev/null
+++ b/receme/src/ralgebra.rs
@@ -0,0 +1,25 @@
+//! This file defines the behaviours of R-algebras.
+//!
+//! For a functor F, an R-algebra is a natural transformation from F1
+//! to the identity functor, where F1 is the functor that sends T to
+//! F((F(T), T)). This extra F(T) represents the context during the
+//! computations.
+
+use crate::functor::Functor;
+
+/// An R-algebra is a function from F((F(T), T)) to T.
+///
+/// This is a "trait alias". Since Rust does not support trait alias
+/// yet, we define an empty trait with an automatic implementation.
+pub trait RAlgebra<T, F>: FnMut((T, F)) -> T
+where
+ F: Functor<T>,
+{
+}
+
+impl<T, F, R> RAlgebra<T, F> for R
+where
+ F: Functor<T>,
+ R: FnMut((T, F)) -> T,
+{
+}