Skip to content
Browse files

Monad comprehension example

  • Loading branch information...
1 parent 37bb964 commit f7c50cfea13f47bcb8d52b555f20bdbec35f8f7a Edwin Brady committed
Showing with 17 additions and 3 deletions.
  1. +3 −1 CHANGELOG
  2. +11 −2 tutorial/classes.tex
  3. +3 −0 tutorial/examples/classes.idr
  4. BIN tutorial/idris-tutorial.pdf
View
4 CHANGELOG
@@ -1,4 +1,4 @@
-0.1.x to 0.9.0:
+0.1.x to 0.9:
Complete rewrite. User visible changes:
@@ -6,6 +6,8 @@ Complete rewrite. User visible changes:
* New syntax for pairs/dependent pairs
* Added type classes
* Added where clauses
+* Added case expressions, pattern matching let and lambda
+* Added monad comprehensions
* Added cumulativity and universe checking
* Ad-hoc name overloading
- Resolved by type or explicit namespace
View
13 tutorial/classes.tex
@@ -282,8 +282,8 @@ \subsubsection*{Monad comprehensions}
\useverb{monadplus}
\noindent
-In general, a comprehension takes the form \texttt{[ exp | qual ]} where
-\texttt{qual} can be one of:
+In general, a comprehension takes the form \texttt{[ exp | qual1, qual2, ..., qualn ]} where
+\texttt{quali} can be one of:
\begin{itemize}
\item A generator \texttt{x <- e}
@@ -314,5 +314,14 @@ \subsubsection*{Monad comprehensions}
\end{SaveVerbatim}
\useverb{comptrans}
+\noindent
+Using monad comprehensions, an alternative definition for \texttt{m\_add} would be:
+
+\begin{SaveVerbatim}{maddb}
+
+m_add : Maybe Int -> Maybe Int -> Maybe Int;
+m_add x y = [ x' + y' | x' <- x, y' <- y ];
+\end{SaveVerbatim}
+\useverb{maddb}
View
3 tutorial/examples/classes.idr
@@ -4,5 +4,8 @@ m_add x y = do { x' <- x; -- Extract value from x
return (x' + y'); -- Add them
};
+m_add' : Maybe Int -> Maybe Int -> Maybe Int;
+m_add' x y = [ x' + y' | x' <- x, y' <- y ];
+
sortAndShow : (Ord a, Show a) => List a -> String;
sortAndShow xs = show (sort xs);
View
BIN tutorial/idris-tutorial.pdf
Binary file not shown.

0 comments on commit f7c50cf

Please sign in to comment.
Something went wrong with that request. Please try again.