Monad interface
The traits that give a monad marker its meaning for monadic handler composition.
Overview
Context-Generic Programming (CGP) composes handlers into pipelines at compile time, and a
monadic pipeline chains handlers where each step may continue or
short-circuit, the ?-style behaviour, expressed as composable
providers. A monad in CGP is a zero-sized marker, and these
four traits are what give that marker meaning. They are plain traits rather than
CGP components: they lack a generated
provider trait and are never wired. The
monad providers consume them as ordinary bounds while folding a
pipeline at compile time, so you name a trait here only when defining a monad of your own. Import
each from cgp::extra::monad::traits.
They split into the pair that folds the pipeline and the pair that runs one step.
The folding pair decides the shape of the composed provider. MonadicBind turns
a continuation into one bind step, and MonadicTrans stacks one monad over another
so a pipeline can peel a nested Result.
The step-running pair brackets one bind step. ContainsValue names the value a
monad threads forward out of a step's output, and LiftValue puts a value back into
the output type on either branch.
The ideas behind them
- Monadic handlers: why a pipeline short-circuits and how the monads compose.
An AI agent wrote this page using the CGP knowledge base. Its content was verified against the library's source. See How AI is used in this project.