comparison doc/manual.tex @ 553:effd620d90da

The structure of web applications
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Dec 2008 15:01:21 -0500
parents 215d719836dc
children 193fe8836419
comparison
equal deleted inserted replaced
552:215d719836dc 553:effd620d90da
1328 \textrm{Attribute value} & v &::=& \ell & \textrm{literal value} \\ 1328 \textrm{Attribute value} & v &::=& \ell & \textrm{literal value} \\
1329 &&& \{e\} & \textrm{computed value} \\ 1329 &&& \{e\} & \textrm{computed value} \\
1330 \end{array}$$ 1330 \end{array}$$
1331 1331
1332 1332
1333 \section{The Structure of Web Applications}
1334
1335 A web application is built from a series of modules, with one module, the last one appearing in the \texttt{.urp} file, designated as the main module. The signature of the main module determines the URL entry points to the application. Such an entry point should have type $\mt{unit} \to \mt{transaction} \; \mt{page}$, where $\mt{page}$ is a type synonym for top-level HTML pages, defined in $\mt{Basis}$. If such a function is at the top level of main module $M$, it will be accessible at URI \texttt{/M/f}, and so on for more deeply-nested functions, as described in Section \ref{tag} below.
1336
1337 When the standalone web server receives a request for a known page, it calls the function for that page, ``running'' the resulting transaction to produce the page to return to the client. Pages link to other pages with the \texttt{link} attribute of the \texttt{a} HTML tag. A link has type $\mt{transaction} \; \mt{page}$, and the semantics of a link are that this transaction should be run to compute the result page, when the link is followed. Link targets are assigned URL names in the same way as top-level entry points.
1338
1339 HTML forms are handled in a similar way. The $\mt{action}$ attribute of a $\mt{submit}$ form tag takes a value of type $\$\mt{use} \to \mt{transaction} \; \mt{page}$, where $\mt{use}$ is a kind-$\{\mt{Type}\}$ record of the form fields used by this action handler. Action handlers are assigned URL patterns in the same way as above.
1340
1341 For both links and actions, direct arguments and local variables mentioned implicitly via closures are automatically included in serialized form in URLs, in the order in which they appeared in the source code.
1342
1343
1333 \section{Compiler Phases} 1344 \section{Compiler Phases}
1334 1345
1335 The Ur/Web compiler is unconventional in that it relies on a kind of \emph{heuristic compilation}. Not all valid programs will compile successfully. Informally, programs fail to compile when they are ``too higher order.'' Compiler phases do their best to eliminate different kinds of higher order-ness, but some programs just won't compile. This is a trade-off for producing very efficient executables. Compiled Ur/Web programs use native C representations and require no garbage collection. 1346 The Ur/Web compiler is unconventional in that it relies on a kind of \emph{heuristic compilation}. Not all valid programs will compile successfully. Informally, programs fail to compile when they are ``too higher order.'' Compiler phases do their best to eliminate different kinds of higher order-ness, but some programs just won't compile. This is a trade-off for producing very efficient executables. Compiled Ur/Web programs use native C representations and require no garbage collection.
1336 1347
1337 In this section, we step through the main phases of compilation, noting what consequences each phase has for effective programming. 1348 In this section, we step through the main phases of compilation, noting what consequences each phase has for effective programming.
1362 1373
1363 \subsection{Shake} 1374 \subsection{Shake}
1364 1375
1365 Remove all definitions not needed to run the page handlers that are visible in the signature of the last module listed in the \texttt{.urp} file. 1376 Remove all definitions not needed to run the page handlers that are visible in the signature of the last module listed in the \texttt{.urp} file.
1366 1377
1367 \subsection{Tag} 1378 \subsection{\label{tag}Tag}
1368 1379
1369 Assign a URL name to each link and form action. It is important that these links and actions are written as applications of named functions, because such names are used to generate URL patterns. A URL pattern has a name built from the full module path of the named function, followed by the function name, with all pieces separated by slashes. The path of a functor application is based on the name given to the result, rather than the path of the functor itself. 1380 Assign a URL name to each link and form action. It is important that these links and actions are written as applications of named functions, because such names are used to generate URL patterns. A URL pattern has a name built from the full module path of the named function, followed by the function name, with all pieces separated by slashes. The path of a functor application is based on the name given to the result, rather than the path of the functor itself.
1370 1381
1371 \subsection{Reduce} 1382 \subsection{Reduce}
1372 1383