std.monad
Implementation of the Monad
type
Types
#[implicit]
type Monad m = {
applicative : Applicative m,
flat_map : forall a b . (a -> m b) -> m a -> m b
}
A generalised interface for imperatively sequencing actions
Values
This can be seen as akin to sequential variable binding in an imperative language. For example in Javascript:
var x = call_fallible("hello");
do_something(x);
In gluon this would look like:
result.monad.flat_map (\x -> do_something x) (call_fallible "hello")
Note that it is sometimes more ergonomic to use the (>>=)
operator:
let { (>>=) } = import! std.prelude
call_fallible "hello" >>= (\x -> do_something x)
Note
- Known as
(=<<) or
flip (>>=)` in Haskell - Known as
Option::and_then
andResult::and_then
in Rust