monad-laws: Monad Laws

monad-lawsR Documentation

Monad Laws

Description

Classes implementing bind() are expected to satisfy three monad laws: left identity, right identity, and associativity.

Arguments

pure

The function to wrap a value in the monad.

h, g

Monadic functions. Functions that return monadic objects.

a

Any object.

m

A monadic object.

Details

The Haskell monad laws can be translated into R as follows:

Left identity:

pure(a) %>-% h is equal to h(a).

Right identity:

m %>-% pure is equal to m.

Associativity:

(m %>-% g) %>-% h is equal to ⁠m %>-% \(x) g(x) %>-% h⁠.

References

https://wiki.haskell.org/Monad_laws

See Also

Other implementation laws: functor-laws


monad documentation built on Oct. 28, 2024, 5:07 p.m.