next up previous contents
Next: Transactions Up: The Ur/Web Standard Library Previous: The Ur/Web Standard Library   Contents


The Ur Basis defines the monad constructor class from Haskell.

\mathsf{class} \; \mathsf{monad} :: \mathsf...
\hspace{.1in} \to \mathsf{monad} \; \mathsf{m}

The Ur/Web compiler provides syntactic sugar for monads, similar to Haskell's do notation. An expression $ x \leftarrow e_1; e_2$ is desugared to $ \mathsf{bind} \; e_1 \; (\lambda x \Rightarrow e_2)$ , and an expression $ e_1; e_2$ is desugared to $ \mathsf{bind} \; e_1 \; (\lambda () \Rightarrow e_2)$ . Note a difference from Haskell: as the $ e_1; e_2$ case desugaring involves a function with $ ()$ as its formal argument, the type of $ e_1$ must be of the form $ m \; \{\}$ , rather than some arbitrary $ m \; t$ .

The syntactic sugar also allows $ p \leftarrow e_1; e_2$ for $ p$ a pattern. The pattern should be guaranteed to match any value of the corresponding type, or there will be a compile-time error.