diff options
author | JSDurand <mmemmew@gmail.com> | 2022-11-15 12:01:28 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-11-15 12:01:28 +0800 |
commit | cb7bcfad4ab0041aaf3fde3185e27ee46bb37788 (patch) | |
tree | a4fd99b138b72617b6c4c2b04f5d2655d0fedcc5 /receme/src/coralgebra.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/coralgebra.rs')
-rw-r--r-- | receme/src/coralgebra.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/receme/src/coralgebra.rs b/receme/src/coralgebra.rs new file mode 100644 index 0000000..a4a73d2 --- /dev/null +++ b/receme/src/coralgebra.rs @@ -0,0 +1,28 @@ +//! This file defines the behaviours of R-co-algebras. +//! +//! For a functor F, an R-co-algebra is a natural transformation from +//! the identity functor to F1, where F1 is the functor that sends T +//! to F(F(T) + T), where the + is the categorical co-product, +//! represented in Rust as `Result`. And the F(T) variant means to +//! short-circuit the expansion. + +use crate::functor::Functor; + +/// An R-co-algebra is a function from T to F(Result<F(T), 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 Coralgebra<T, F, G>: FnMut(T) -> G +where + F: Functor<T>, + G: Functor<Result<T, F>>, +{ +} + +impl<T, F, G, R> Coralgebra<T, F, G> for R +where + F: Functor<T>, + G: Functor<Result<T, F>>, + R: FnMut(T) -> G, +{ +} |