pub enum Freer<F, A>where
F: HKT + 'static,
A: 'static,{
Pure(A),
Impure(Box<dyn FreerStep<F, A>>),
}Expand description
Freer Monad — a free monad that does not require F: Functor.
Freer<F, A> stores a computation as a tree of effect steps, each
containing ∃B. (F B, B → Freer F A). The existential B is erased
via a dyn-safe trait, deferring the Functor requirement to fold_map.
Pure(a) — a finished computation
Impure(step) — an effect step with continuation§When to use Freer vs Free
- Use
Free<F, A>whenF: Functor— simpler, no overhead. - Use
Freer<F, A>whenFis NOT a functor, or when you want to build computations without the functor constraint.
Variants§
Pure(A)
A pure value — the computation is finished.
Impure(Box<dyn FreerStep<F, A>>)
An effect step with erased intermediate type.
Implementations§
Source§impl<F, A> Freer<F, A>where
F: HKT + 'static,
A: 'static,
impl<F, A> Freer<F, A>where
F: HKT + 'static,
A: 'static,
Sourcepub fn lift_f(fa: <F as HKT>::Of<A>) -> Freer<F, A>
pub fn lift_f(fa: <F as HKT>::Of<A>) -> Freer<F, A>
Lift a single effect F<A> into the freer monad.
No F: Functor required.
Sourcepub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> Freer<F, B>where
B: 'static,
pub fn fmap<B>(self, f: impl Fn(A) -> B + 'static) -> Freer<F, B>where
B: 'static,
Map a function over the result of this computation.
No F: Functor required. Implemented via chain.
Sourcepub fn chain<B>(self, f: impl Fn(A) -> Freer<F, B> + 'static) -> Freer<F, B>where
B: 'static,
pub fn chain<B>(self, f: impl Fn(A) -> Freer<F, B> + 'static) -> Freer<F, B>where
B: 'static,
Monadic bind — sequence this computation with a function that produces the next computation.
No F: Functor required. The closure is shared via Rc across
deferred chain layers.
Auto Trait Implementations§
impl<F, A> !RefUnwindSafe for Freer<F, A>
impl<F, A> !Send for Freer<F, A>
impl<F, A> !Sync for Freer<F, A>
impl<F, A> !UnwindSafe for Freer<F, A>
impl<F, A> Freeze for Freer<F, A>where
A: Freeze,
impl<F, A> Unpin for Freer<F, A>where
A: Unpin,
impl<F, A> UnsafeUnpin for Freer<F, A>where
A: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more