summaryrefslogtreecommitdiff
path: root/receme/src/ralgebra.rs
blob: 989089e40c4b6c225ba3797ebe10c6eeae3a0c70 (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
//! 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,
{
}