remove stackless defaults

This commit is contained in:
AF 2023-07-31 16:50:17 +00:00
parent 1959b1833e
commit d3c55ff1bd

View File

@ -11,14 +11,14 @@ use std::{cell::Cell, rc::Rc};
use crate::func::class_prelude::*; use crate::func::class_prelude::*;
use crate::func::derivations::{ApplicativeLA2ViaSeq, ApplicativeTupleViaLA2}; use crate::func::derivations::{ApplicativeLA2ViaSeq, ApplicativeTupleViaLA2};
struct Wrapper<'a, F>(F, PhantomData<&'a ()>);
trait Atom { trait Atom {
fn next<'t>(self: Box<Self>) -> Oet<'t> fn next<'t>(self: Box<Self>) -> Oet<'t>
where where
Self: 't; Self: 't;
} }
struct Wrapper<'a, F>(F, PhantomData<&'a ()>);
fn atom<'a, F: 'a + FnOnce() -> Oet<'a>>(f: F) -> EvalTree<'a> { fn atom<'a, F: 'a + FnOnce() -> Oet<'a>>(f: F) -> EvalTree<'a> {
EvalTree::Atom(Box::new(Wrapper(f, PhantomData))) EvalTree::Atom(Box::new(Wrapper(f, PhantomData)))
} }
@ -157,18 +157,6 @@ impl<'a> Functor<'a> for StacklessInstance {
fn fmap<A: 'a, B: 'a>(fa: Self::F<A>, f: impl 'a + FnOnce(A) -> B) -> Self::F<B> { fn fmap<A: 'a, B: 'a>(fa: Self::F<A>, f: impl 'a + FnOnce(A) -> B) -> Self::F<B> {
fa.map(f) fa.map(f)
} }
fn replace<A: 'a, B: 'a>(fa: Self::F<A>, b: B) -> Self::F<B> {
Stackless(Box::new(|takesb| {
Some(EvalTree::Composite(
batom(move || fa.call(drop)),
batom(move || {
takesb(b);
None
}),
))
}))
}
} }
impl<'a> Pure<'a> for StacklessInstance { impl<'a> Pure<'a> for StacklessInstance {
@ -201,25 +189,7 @@ impl<'a> ApplicativeTuple<'a> for StacklessInstance {
impl<'a> ApplicativeSelect<'a> for StacklessInstance {} impl<'a> ApplicativeSelect<'a> for StacklessInstance {}
impl<'a> Applicative<'a> for StacklessInstance { impl<'a> Applicative<'a> for StacklessInstance {}
fn discard_first<A: 'a, B: 'a>(fa: Self::F<A>, fb: Self::F<B>) -> Self::F<B> {
Stackless(Box::new(|takesb| {
Some(EvalTree::Composite(
batom(|| fa.call(drop)),
batom(|| fb.0(takesb)),
))
}))
}
fn discard_second<A: 'a, B: 'a>(fa: Self::F<A>, fb: Self::F<B>) -> Self::F<A> {
Stackless(Box::new(|takesa| {
Some(EvalTree::Composite(
batom(|| fa.0(takesa)),
batom(|| fb.call(drop)),
))
}))
}
}
impl<'a> Monad<'a> for StacklessInstance { impl<'a> Monad<'a> for StacklessInstance {
fn bind<A: 'a, B: 'a>(fa: Self::F<A>, f: impl 'a + FnOnce(A) -> Self::F<B>) -> Self::F<B> { fn bind<A: 'a, B: 'a>(fa: Self::F<A>, f: impl 'a + FnOnce(A) -> Self::F<B>) -> Self::F<B> {
@ -234,20 +204,6 @@ impl<'a> Monad<'a> for StacklessInstance {
}) })
}) })
} }
fn join<A: 'a>(ffa: Self::F<Self::F<A>>) -> Self::F<A> {
Stackless(Box::new(|takesa| {
let cell_l = Rc::new(Cell::new(None));
let cell_r = cell_l.clone();
Some(EvalTree::Composite(
batom(move || ffa.call(move |a| set_cell(cell_l, a))),
batom(move || {
let stackless = get_cell(cell_r);
satom(|| stackless.0(takesa))
}),
))
}))
}
} }
#[cfg(test)] #[cfg(test)]