@@ -190,6 +190,8 @@ sortAndShow xs = show (sort xs);
190190
191191\subsection{Monads and \texttt{do}-notation}
192192
193+\label{sec:monad}
194+
193195So far, we have seen single parameter type classes, where the parameter is of type
194196\texttt{Set}. In general, there can be any number (greater than 0) of parameters,
195197and the parameters can have \remph{any} type.
@@ -263,3 +265,54 @@ Nothing : Maybe Int
263265
264266\end{SaveVerbatim}
265267\useverb{maybeaddt}
268+
269+\subsubsection*{Monad comprehensions}
270+
271+The list comprehension notation we saw in Section \ref{sec:listcomp} is more
272+general, and applies to anything which is an instance of \texttt{MonadPlus}:
273+
274+\begin{SaveVerbatim}{monadplus}
275+
276+class Monad m => MonadPlus (m : Set -> Set) where {
277+ mplus : m a -> m a -> m a;
278+ mzero : m a;
279+}
280+
281+\end{SaveVerbatim}
282+\useverb{monadplus}
283+
284+\noindent
285+In general, a comprehension takes the form \texttt{[ exp | qual ]} where
286+\texttt{qual} can be one of:
287+
288+\begin{itemize}
289+\item A generator \texttt{x <- e}
290+\item A \emph{guard}, which is an expression of type \texttt{Bool}
291+\item A let binding \texttt{let x = e}
292+\end{itemize}
293+
294+\noindent
295+To translate a comprehension \texttt{[exp | qual1, qual2, ..., qualn]}, first
296+any qualifier
297+\texttt{qual} which is a \emph{guard} is translated to \texttt{guard qual}, using
298+the following function:
299+
300+\begin{SaveVerbatim}{guardq}
301+
302+guard : MonadPlus m => Bool -> m ()
303+
304+\end{SaveVerbatim}
305+\useverb{guardq}
306+
307+\noindent
308+Then the comprehension is converted to \texttt{do} notation:
309+
310+\begin{SaveVerbatim}{comptrans}
311+
312+do { qual1; qual2; ...; qualn; return exp; }
313+
314+\end{SaveVerbatim}
315+\useverb{comptrans}
316+
317+
318+