From cb7bcfad4ab0041aaf3fde3185e27ee46bb37788 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 15 Nov 2022 12:01:28 +0800 Subject: 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. --- receme/src/parapo.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 receme/src/parapo.rs (limited to 'receme/src/parapo.rs') diff --git a/receme/src/parapo.rs b/receme/src/parapo.rs new file mode 100644 index 0000000..11cc613 --- /dev/null +++ b/receme/src/parapo.rs @@ -0,0 +1,44 @@ +//! This file defines behaviours of paramorphisms and apomorphisms. +//! +//! A paramorphism is a generalization of a catamorphism. Instead of +//! using an algebra, which is a function from F(T) to T, we use an +//! R-algebra, which is a function from F(T, F(T)) to T. The extra +//! F(T) represents the contexts where the collapsing happens. +//! +//! An apomorphism is a generalization of anamorphism. It is the +//! categorical dual of a paramorphism. So it uses an R-co-algebra, +//! which is a function from T to F(F(T) + T), where the latter sum is +//! the categorical co-product. + +use crate::{coralgebra::Coralgebra, functor::Functor, ralgebra::RAlgebra}; + +/// A type that implements Para is capable of being collapsed to a +/// single value by use of an R-Algebra. +/// +/// The paramorphism consumes `self`. +pub trait Para +where + F: Functor, + R: RAlgebra, +{ + /// A paramorphism takes a recursive structure and an R-algebra + /// for that recursive structure, and returns a single, flat, + /// collapsed value. + fn para(self, ralg: R) -> T; +} + +/// A type that implements Apo is capable of being expanded from a +/// flat value by use of an R-co-algebra. +/// +/// The apomorphism consumes `self`. +pub trait Apo +where + F: Functor, + G: Functor>, + C: Coralgebra, +{ + /// An apomorphism takes single, flat, collapsed value and an + /// R-co-algebra for a recursive structure, and returns that + /// recursive structure. + fn apo(value: T, rcoalg: C) -> Self; +} -- cgit v1.2.3-18-g5258