Skip to contents

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

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.

See also

Other implementation laws: functor-laws