comparison doc/manual.tex @ 1548:76dab73304a5

Document monadic shorthands
author Adam Chlipala <adam@chlipala.net>
date Wed, 24 Aug 2011 08:18:09 -0400
parents a99b743a3087
children 5175bed443f9
comparison
equal deleted inserted replaced
1547:553a5cc3a4b5 1548:76dab73304a5
1387 \hspace{.1in} \to \{\mt{Return} : \mt{t} ::: \mt{Type} \to \mt{t} \to \mt{m} \; \mt{t}, \\ 1387 \hspace{.1in} \to \{\mt{Return} : \mt{t} ::: \mt{Type} \to \mt{t} \to \mt{m} \; \mt{t}, \\
1388 \hspace{.3in} \mt{Bind} : \mt{t1} ::: \mt{Type} \to \mt{t2} ::: \mt{Type} \to \mt{m} \; \mt{t1} \to (\mt{t1} \to \mt{m} \; \mt{t2}) \to \mt{m} \; \mt{t2}\} \\ 1388 \hspace{.3in} \mt{Bind} : \mt{t1} ::: \mt{Type} \to \mt{t2} ::: \mt{Type} \to \mt{m} \; \mt{t1} \to (\mt{t1} \to \mt{m} \; \mt{t2}) \to \mt{m} \; \mt{t2}\} \\
1389 \hspace{.1in} \to \mt{monad} \; \mt{m} 1389 \hspace{.1in} \to \mt{monad} \; \mt{m}
1390 \end{array}$$ 1390 \end{array}$$
1391 1391
1392 The Ur/Web compiler provides syntactic sugar for monads, similar to Haskell's \cd{do} notation. An expression $x \leftarrow e_1; e_2$ is desugarded to $\mt{bind} \; e_1 \; (\lambda x \Rightarrow e_2)$, and an expression $e_1; e_2$ is desugared to $\mt{bind} \; e_1 \; (\lambda () \Rightarrow e_2)$.
1393
1392 \subsection{Transactions} 1394 \subsection{Transactions}
1393 1395
1394 Ur is a pure language; we use Haskell's trick to support controlled side effects. The standard library defines a monad $\mt{transaction}$, meant to stand for actions that may be undone cleanly. By design, no other kinds of actions are supported. 1396 Ur is a pure language; we use Haskell's trick to support controlled side effects. The standard library defines a monad $\mt{transaction}$, meant to stand for actions that may be undone cleanly. By design, no other kinds of actions are supported.
1395 $$\begin{array}{l} 1397 $$\begin{array}{l}
1396 \mt{con} \; \mt{transaction} :: \mt{Type} \to \mt{Type} \\ 1398 \mt{con} \; \mt{transaction} :: \mt{Type} \to \mt{Type} \\