43 lines
985 B
Rust
43 lines
985 B
Rust
use super::*;
|
|
|
|
pub type WrapC<'a, A, Ctx> = Wrap<'a, A, <Ctx as FunctorContext<'a>>::T>;
|
|
|
|
pub trait FunctorContext<'a>: 'a {
|
|
type T: WeakFunctor<'a>;
|
|
}
|
|
|
|
pub trait FunctorContextExt<'a>: FunctorContext<'a> {
|
|
fn fmap<A: 'a, B: 'a>(fa: WrapC<'a, A, Self>, f: impl 'a + FnOnce(A) -> B) -> WrapC<'a, B, Self>
|
|
where
|
|
Self::T: Functor<'a>,
|
|
{
|
|
<Self::T as Functor>::fmap(fa, f)
|
|
}
|
|
|
|
fn pure<A: 'a>(a: A) -> WrapC<'a, A, Self>
|
|
where
|
|
Self::T: Pure<'a>,
|
|
{
|
|
<Self::T as Pure>::pure(a)
|
|
}
|
|
|
|
fn bind<A: 'a, B: 'a>(
|
|
fa: WrapC<'a, A, Self>,
|
|
f: impl 'a + FnOnce(A) -> WrapC<'a, B, Self>,
|
|
) -> WrapC<'a, B, Self>
|
|
where
|
|
Self::T: Monad<'a>,
|
|
{
|
|
<Self::T as Monad>::bind(fa, f)
|
|
}
|
|
|
|
fn fail<A: 'a, E: 'a>(e: E) -> WrapC<'a, A, Self>
|
|
where
|
|
Self::T: Fail<'a, E>,
|
|
{
|
|
<Self::T as Fail<_>>::fail(e)
|
|
}
|
|
}
|
|
|
|
impl<'a, Ctx: FunctorContext<'a>> FunctorContextExt<'a> for Ctx {}
|