move derivations into a separate module
This commit is contained in:
parent
8928d25e68
commit
4ad05fbe7c
23
src/func.rs
23
src/func.rs
@ -1,6 +1,7 @@
|
||||
pub mod classes;
|
||||
pub mod clone_func;
|
||||
pub mod copy_func;
|
||||
pub mod derivations;
|
||||
#[cfg(test)]
|
||||
pub mod test_suite;
|
||||
#[cfg(test)]
|
||||
@ -85,16 +86,6 @@ pub trait ApplicativeSeq: Functor {
|
||||
) -> Self::F<'a, B>
|
||||
where
|
||||
Self: 'a;
|
||||
fn _la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||
f: impl 'a + FnOnce(A, B) -> C,
|
||||
fa: Self::F<'a, A>,
|
||||
fb: Self::F<'a, B>,
|
||||
) -> Self::F<'a, C>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::seq(Self::fmap(|a| |b| f(a, b), fa), fb)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ApplicativeLA2: Functor {
|
||||
@ -105,18 +96,6 @@ pub trait ApplicativeLA2: Functor {
|
||||
) -> Self::F<'a, C>
|
||||
where
|
||||
Self: 'a;
|
||||
fn _seq<'a, A: 'a, B: 'a>(
|
||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||
fa: Self::F<'a, A>,
|
||||
) -> Self::F<'a, B>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::la2(|f, a| f(a), ff, fa)
|
||||
}
|
||||
fn _tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)> {
|
||||
Self::la2(|a, b| (a, b), fa, fb)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ApplicativeTuple: Functor {
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::{cell::Cell, rc::Rc};
|
||||
|
||||
use crate::func::derivations::*;
|
||||
use crate::func::*;
|
||||
|
||||
enum EvalTree<'a> {
|
||||
@ -29,9 +30,7 @@ impl<'a> EvalTree<'a> {
|
||||
|
||||
type StackessDyn<'a, A> = dyn 'a + FnOnce(Box<dyn 'a + FnOnce(A)>) -> Oet<'a>;
|
||||
|
||||
pub struct Stackless<'a, A: 'a>(
|
||||
Box<StackessDyn<'a, A>>,
|
||||
);
|
||||
pub struct Stackless<'a, A: 'a>(Box<StackessDyn<'a, A>>);
|
||||
|
||||
fn set_cell<A>(cell: Rc<Cell<Option<A>>>, a: A) {
|
||||
if cell.replace(Some(a)).is_some() {
|
||||
@ -159,7 +158,7 @@ impl ApplicativeLA2 for StacklessClass {
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::_la2(f, fa, fb)
|
||||
Self::_la2_via_seq(f, fa, fb)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,7 +167,7 @@ impl ApplicativeTuple for StacklessClass {
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::_tuple((fa, fb))
|
||||
Self::_tuple_via_la2((fa, fb))
|
||||
}
|
||||
}
|
||||
|
||||
|
64
src/func/derivations.rs
Normal file
64
src/func/derivations.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use crate::func::*;
|
||||
|
||||
pub trait ApplicativeLA2ViaSeq: ApplicativeSeq {
|
||||
fn _la2_via_seq<'a, A: 'a, B: 'a, C: 'a>(
|
||||
f: impl 'a + FnOnce(A, B) -> C,
|
||||
fa: Self::F<'a, A>,
|
||||
fb: Self::F<'a, B>,
|
||||
) -> Self::F<'a, C>
|
||||
where
|
||||
Self: 'a;
|
||||
}
|
||||
|
||||
impl<T: ApplicativeSeq> ApplicativeLA2ViaSeq for T {
|
||||
fn _la2_via_seq<'a, A: 'a, B: 'a, C: 'a>(
|
||||
f: impl 'a + FnOnce(A, B) -> C,
|
||||
fa: Self::F<'a, A>,
|
||||
fb: Self::F<'a, B>,
|
||||
) -> Self::F<'a, C>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::seq(Self::fmap(|a| |b| f(a, b), fa), fb)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ApplicativeSeqViaLA2: ApplicativeLA2 {
|
||||
fn _seq_via_la2<'a, A: 'a, B: 'a>(
|
||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||
fa: Self::F<'a, A>,
|
||||
) -> Self::F<'a, B>
|
||||
where
|
||||
Self: 'a;
|
||||
}
|
||||
|
||||
impl<T: ApplicativeLA2> ApplicativeSeqViaLA2 for T {
|
||||
fn _seq_via_la2<'a, A: 'a, B: 'a>(
|
||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||
fa: Self::F<'a, A>,
|
||||
) -> Self::F<'a, B>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::la2(|f, a| f(a), ff, fa)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ApplicativeTupleViaLA2: ApplicativeLA2 {
|
||||
fn _tuple_via_la2<'a, A: 'a, B: 'a>(
|
||||
fab: (Self::F<'a, A>, Self::F<'a, B>),
|
||||
) -> Self::F<'a, (A, B)>
|
||||
where
|
||||
Self: 'a;
|
||||
}
|
||||
|
||||
impl<T: ApplicativeLA2> ApplicativeTupleViaLA2 for T {
|
||||
fn _tuple_via_la2<'a, A: 'a, B: 'a>(
|
||||
(fa, fb): (Self::F<'a, A>, Self::F<'a, B>),
|
||||
) -> Self::F<'a, (A, B)>
|
||||
where
|
||||
Self: 'a,
|
||||
{
|
||||
Self::la2(|a, b| (a, b), fa, fb)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user