summaryrefslogtreecommitdiff
path: root/receme/src/catana.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-11-15 12:01:28 +0800
committerJSDurand <mmemmew@gmail.com>2022-11-15 12:01:28 +0800
commitcb7bcfad4ab0041aaf3fde3185e27ee46bb37788 (patch)
treea4fd99b138b72617b6c4c2b04f5d2655d0fedcc5 /receme/src/catana.rs
Initial commit
Basic GNU standard files are added, and we now stop worrying about monadic anamorphisms. The current focus is on testing the correctness of the algorithm, so I need convenient support for manipulating, interpreting, examining, and per chance animating nondeterministic automata.
Diffstat (limited to 'receme/src/catana.rs')
-rw-r--r--receme/src/catana.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/receme/src/catana.rs b/receme/src/catana.rs
new file mode 100644
index 0000000..e3d4728
--- /dev/null
+++ b/receme/src/catana.rs
@@ -0,0 +1,27 @@
+//! This file defines behaviours of catamorphisms and anamorphisms.
+//!
+//! A catamorphism collapses a recursive structure into a flat value,
+//! whereas an anamorphism expands a value into a recursive structure.
+
+use crate::{algebra::Algebra, coalgebra::Coalgebra, functor::Functor};
+
+/// A type that implements Cata is capable of being collapsed into a single value.
+///
+/// The catamorphism consumes `self`.
+pub trait Cata<T, F: Functor<T>, A: Algebra<T, F>> {
+ /// A catamorphism takes a recursive structure and an algebra for
+ /// the recursive structure, and returns a single, flat, collapsed
+ /// value.
+ fn cata(self, alg: A) -> T;
+}
+
+/// A type that implements Ana is capable of being expanded from a
+/// flat value.
+///
+/// The anamorphism consumes `self`.
+pub trait Ana<T, F: Functor<T>, C: Coalgebra<T, F>> {
+ /// An anamorphism takes a single, flat, collapsed value and a
+ /// co-algebra for a recursive structure, and returns that
+ /// recursive structure.
+ fn ana(value: T, coalg: C) -> Self;
+}