control v0.1.0 Control.Monad protocol

A monad is essentially a value with a context.

Just as applicative functors are special versions of functors, monads are special versions of applicative functors.

Laws

All implementations of Control.Monad should obey the following implicit laws:

type |> return(x) ~>> f = f(x)
m ~>> return            = m
(m ~>> f) ~>> g         = m ~>> &(f(&1) ~>> g)

where m is a monad, x is a value, and f and g are both functions that return monadic values.

Link to this section Summary

Functions

bind is similar to function application, only instead of taking a normal value and feeding it to a normal function, it takes a monadic value (that is, a value with a context) and feeds it to a function that takes a normal value but returns a monadic value

return takes a value and puts it in a minimal default context that still holds that value. In other words, it takes something and wraps it in a monad

Link to this section Types

Link to this type t()
t() :: term()

Link to this section Functions

Link to this function bind(m, fun)
bind(t(), (term() -> t())) :: t()

bind is similar to function application, only instead of taking a normal value and feeding it to a normal function, it takes a monadic value (that is, a value with a context) and feeds it to a function that takes a normal value but returns a monadic value.

Link to this function return(m, value \\ nil)
return(t(), term()) :: t()

return takes a value and puts it in a minimal default context that still holds that value. In other words, it takes something and wraps it in a monad.