Mercurial > urweb
comparison doc/manual.tex @ 542:31482f333362
Start of Ur/Web library
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 06 Dec 2008 13:04:48 -0500 |
parents | 2bf2d0e0fb61 |
children | c01415a171ed |
comparison
equal
deleted
inserted
replaced
541:2bf2d0e0fb61 | 542:31482f333362 |
---|---|
913 \subsection{Implicit Arguments in Functor Applications} | 913 \subsection{Implicit Arguments in Functor Applications} |
914 | 914 |
915 Constructor, constraint, and type class witness members of structures may be omitted, when those structures are used in contexts where their assigned signatures imply how to fill in those missing members. This feature combines well with reverse-engineering to allow for uses of complicated meta-programming functors with little more code than would be necessary to invoke an untyped, ad-hoc code generator. | 915 Constructor, constraint, and type class witness members of structures may be omitted, when those structures are used in contexts where their assigned signatures imply how to fill in those missing members. This feature combines well with reverse-engineering to allow for uses of complicated meta-programming functors with little more code than would be necessary to invoke an untyped, ad-hoc code generator. |
916 | 916 |
917 | 917 |
918 \section{The Ur Standard Library} | |
919 | |
920 The built-in parts of the Ur/Web standard library are described by the signature in \texttt{lib/basis.urs} in the distribution. A module $\mt{Basis}$ ascribing to that signature is available in the initial environment, and every program is implicitly prefixed by $\mt{open} \; \mt{Basis}$. | |
921 | |
922 Additionally, other common functions that are definable within Ur are included in \texttt{lib/top.urs} and \texttt{lib/top.ur}. This $\mt{Top}$ module is also opened implicitly. | |
923 | |
924 The idea behind Ur is to serve as the ideal host for embedded domain-specific languages. For now, however, the ``generic'' functionality is intermixed with Ur/Web-specific functionality, including in these two library modules. We hope that these generic library components have types that speak for themselves. The next section introduces the Ur/Web-specific elements. Here, we only give the type declarations from the beginning of $\mt{Basis}$. | |
925 | |
926 $$\begin{array}{l} | |
927 \mt{type} \; \mt{int} \\ | |
928 \mt{type} \; \mt{float} \\ | |
929 \mt{type} \; \mt{string} \\ | |
930 \mt{type} \; \mt{time} \\ | |
931 \\ | |
932 \mt{type} \; \mt{unit} = \{\} \\ | |
933 \\ | |
934 \mt{datatype} \; \mt{bool} = \mt{False} \mid \mt{True} \\ | |
935 \\ | |
936 \mt{datatype} \; \mt{option} \; \mt{t} = \mt{None} \mid \mt{Some} \; \mt{of} \; \mt{t} | |
937 \end{array}$$ | |
938 | |
939 | |
940 \section{The Ur/Web Standard Library} | |
941 | |
942 \subsection{Transactions} | |
943 | |
944 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. | |
945 | |
946 $$\begin{array}{l} | |
947 \mt{con} \; \mt{transaction} :: \mt{Type} \to \mt{Type} \\ | |
948 \\ | |
949 \mt{val} \; \mt{return} : \mt{t} ::: \mt{Type} \to \mt{t} \to \mt{transaction} \; \mt{t} \\ | |
950 \mt{val} \; \mt{bind} : \mt{t_1} ::: \mt{Type} \to \mt{t_2} ::: \mt{Type} \to \mt{transaction} \; \mt{t_1} \to (\mt{t_1} \to \mt{transaction} \; \mt{t_2}) \to \mt{transaction} \; \mt{t_2} | |
951 \end{array}$$ | |
952 | |
953 \subsection{HTTP} | |
954 | |
955 There are transactions for reading an HTTP header by name and for getting and setting strongly-typed cookies. Cookies may only be created by the $\mt{cookie}$ declaration form, ensuring that they be named consistently based on module structure. | |
956 | |
957 $$\begin{array}{l} | |
958 \mt{val} \; \mt{requestHeader} : \mt{string} \to \mt{transaction} \; (\mt{option} \; \mt{string}) \\ | |
959 \\ | |
960 \mt{con} \; \mt{http\_cookie} :: \mt{Type} \to \mt{Type} \\ | |
961 \mt{val} \; \mt{getCookie} : \mt{t} ::: \mt{Type} \to \mt{http\_cookie} \; \mt{t} \to \mt{transaction} \; (\mt{option} \; \mt{t}) \\ | |
962 \mt{val} \; \mt{setCookie} : \mt{t} ::: \mt{Type} \to \mt{http\_cookie} \; \mt{t} \to \mt{t} \to \mt{transaction} \; \mt{unit} | |
963 \end{array}$$ | |
964 | |
918 \end{document} | 965 \end{document} |