Monads in CS and Math

The purpose of a monad is to introduce a new data type into your language and to integrate it with existing types; a monad augments a pre-existing data type \(A\), creating a new type \(B\).

When describing monads, I will use the following terminology:

A monad consists of two components for achieving this purpose:

A function that converts ordinary values into monadic values

First, in order to create a new data type, each monad has an upgrade function which systematically adds structure to values of the existing data type, \(A\). Because the upgrade function produces enhanced values in a systematic way, the enhanced values constitute a sort of new data type, \(B\).

\(\text{upgrade}:A\rightarrow B\)
A function that enables monadic functions to accept monadic values
Second, each monad has a pipe function which is a protocol for combining a monadic function and a monadic value to produce a monadic value. The pipe function facilitates composition: notice that a collection of monadic functions \(A\rightarrow B\) is composable only if they have been modified by the pipe function to become functions of type \(B\rightarrow B\), otherwise their input and output types do not match.
\(\text{pipe}:B\times B^A\rightarrow B\)
(ns categorical.monad)

Table of Contents

1 Examples of monads

1.1 The nondeterministic monad

We'll implement nondeterministic programming by defining a monad amb that transforms ordinary deterministic functions into functions that ``ambiguously'' return zero or more values.





Date: 2011-07-11 03:07:07 EDT

Author: Robert McIntyre

Org version 7.6 with Emacs version 23

Validate XHTML 1.0