MZero is the identity value for an additive monad: adding it changes nothing, and binding any computation to it produces MZero again. It behaves like zero for the monad’s addition-like operation. section 11.4 section 11.5
An additive monad supplies three related behaviors:
- Adds two monadic values through an operation such as sequence concatenation or probability-distribution merging. section 14.2 section 11.4
- Provides MZero as the additive identity: the empty sequence leaves concatenation unchanged. section 11.4
- Uses MZero to express filtering: retain a value with Unit or reject it with MZero. section 11.4
Empty sequences and distributions
For the sequence monad, MZero is the empty sequence: Select, SelectMany, or Where applied to it remains empty. For a discrete probability distribution, MZero is an empty distribution in which every outcome is impossible. Its implementation returns no support and zero weight; constructors and joint-distribution calculations must account for zero total weight. section 14.2 section 11.4
static M<T> Where<T>(M<T> x, Func<T, bool> predicate) =>
Bind(x, t => predicate(t) ? Unit(t) : MZero);
Expresses generic filtering by binding each value to Unit when the predicate succeeds and MZero otherwise. section 14.2
