pub trait Monad<'a>: Applicative<'a> {
// Required methods
fn bind<A: 'a + Send, B: 'a + Send>(
fa: Self::F<A>,
f: impl 'a + Send + FnOnce(A) -> Self::F<B>
) -> Self::F<B>;
fn iterate<B: 'a + Send>(
f: impl Iterative<'a, T = Self, B = B>
) -> Self::F<B>;
// Provided method
fn join<A: 'a + Send>(ffa: Self::F<Self::F<A>>) -> Self::F<A> { ... }
}Expand description
Equivalent of Haskell’s Monad.
https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Monad.html
Required Methods§
sourcefn bind<A: 'a + Send, B: 'a + Send>(
fa: Self::F<A>,
f: impl 'a + Send + FnOnce(A) -> Self::F<B>
) -> Self::F<B>
fn bind<A: 'a + Send, B: 'a + Send>( fa: Self::F<A>, f: impl 'a + Send + FnOnce(A) -> Self::F<B> ) -> Self::F<B>
Equivalent of Haskell’s >==.
Due to Rust limitations, it’s not a function->function conversion.
For that see derivations::bind.
sourcefn iterate<B: 'a + Send>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<B>
fn iterate<B: 'a + Send>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<B>
Included for optimisation and clarity.
Generally, Monad::bind should be enough implement it.
See StacklessInstance::iterate for a generic, though less-than ideal, blanket implementation.
On practice, you generally shouldn’t be using Monad::bind/Pure::pure/Functor::fmap here.