Dynamic, active documents are particularly troublesome to program within conventional languages. Documents are typically represented in XML or HTML, which use regular-expression like types instead of the familiar sums-of-products datatypes supported by conventional languages. Furthermore, documents tend to include embedded program in a variety of scripting languages, for which conventional languages offer no support at all. It is thus very difficult to verify that these programs generate even syntactically well-formed documents, let alone documents which are valid for their document type definition, and contain only well-typed scripts.; This thesis develops the core type system for a Haskell-like functional programming language that directly supports dynamic, active documents. The first part presents a system of type-indexed rows, that supports many aspects of XML's regular-expression types without abandoning the type features which make functional programming attractive. In particular, type-indexed rows coexist cleanly with higher-order types and parametric polymorphism. The second part presents a system of staged computation, that allows server-side and client-side code to be cleanly separated.; In both cases, the type system can guarantee that only well-formed and valid documents are generated. Hence, not only are document-generating programs easier to write using these systems, in addition they are much more likely to be correct. |