Monad transformer: Difference between revisions

Content deleted Content added
Line 63:
*<math>\mathrm{return} \colon T \rarr \left( T \rarr \mathrm{M} \, A \right) \rarr \mathrm{M} \, A = t \mapsto f \mapsto f \, t</math>
*<math>\mathrm{bind} \colon \left( \left( T \rarr \mathrm{M} \, A \right) \rarr \mathrm{M} \, A \right) \rarr \left( T \rarr \left( T' \rarr \mathrm{M} \, A \right) \rarr \mathrm{M} \, A \right) \rarr \left( T' \rarr \mathrm{M} \, A \right) \rarr \mathrm{M} \, A</math><math>= c \mapsto f \mapsto k \mapsto c \, \left( t \mapsto f \, t \, k \right)</math>
*<math>\mathrm{lift}: \mathrm{M} \, T \rarr (T \rarr \mathrm{M} \, A) \rarr \mathrm{M} \, A = m \mapsto \mathrm{bind} \, m</math>
 
Note that monad transformations are not [[commutative]]: for instance, applying the state transformer to the option monad yields a type <math>S \rarr \left(A \times S \right)^{?}</math> (a computation which may fail and yield no final state), whereas the converse transformation has type <math>S \rarr \left(A^{?} \times S \right)</math> (a computation which yields a final state and an optional return value).