summaryrefslogtreecommitdiff
path: root/receme/src/coralgebra.rs
blob: a4a73d280dc71cb95bf595903ffa11748df12bf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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,
{
}