monad-laws {monad} | R 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 toh(a)
.- Right identity:
m %>-% pure
is equal tom
.- Associativity:
(m %>-% g) %>-% h
is equal tom %>-% \(x) g(x) %>-% h
.
References
https://wiki.haskell.org/Monad_laws
See Also
Other implementation laws:
functor-laws
[Package monad version 0.1.1 Index]