lubeck 0.0.0-prealpha.5-abandoned

Functional programming framework written in cutting edge rust
Documentation
use crate::prelude::Applicative;

use super::Cont;

// thanks tony!
impl<'a, R, A> Applicative<'a, A> for Cont<'a, R, A>
where
    R: 'a,
    A: 'a,
{
    type PureT<T> = T where T: 'a;

    fn pure(a: Self::PureT<A>) -> Self::Type<Self::PureT<A>> {
        Self::Type::<Self::PureT<A>> {
            run_cont: Box::new(|f| f(a)),
        }
    }

    fn app<F, B>(self, f: Self::Type<F>) -> Self::Type<B>
    where
        F: Fn(A) -> B + 'a,
        B: 'a,
    {
        // (B -> R) -> R
        let brr = move |br: Box<dyn FnOnce(B) -> R + 'a>| -> R {
            // (A -> B) -> R
            let abr = move |f: F| -> R {
                // A -> R
                let ar = move |a: A| -> R {
                    // A -> B
                    let b = f(a);
                    // R
                    br(b)
                };
                // (A -> R) -> R
                let arr = self.run_cont;
                // R
                arr(Box::new(ar))
            };
            // ((A -> B) -> R) -> R
            let abrr = f.run_cont;
            // R
            abrr(Box::new(abr))
        };
        Self::Type::<B> {
            run_cont: Box::new(brr),
        }
    }
}