Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / doc / guide / localhost / XML
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>XML</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>XML</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="XML">XML</a> is an <a href="IntermediateLanguage">IntermediateLanguage</a>, translated from <a href="CoreML">CoreML</a> by
32 <a href="Defunctorize">Defunctorize</a>, optimized by <a href="XMLSimplify">XMLSimplify</a>, and translated by
33 <a href="Monomorphise">Monomorphise</a> to <a href="SXML">SXML</a>.</p></div>
34 </div>
35 </div>
36 <div class="sect1">
37 <h2 id="_description">Description</h2>
38 <div class="sectionbody">
39 <div class="paragraph"><p><a href="XML">XML</a> is polymorphic, higher-order, with flat patterns. Every
40 <a href="XML">XML</a> expression is annotated with its type. Polymorphic
41 generalization is made explicit through type variables annotating
42 <span class="monospaced">val</span> and <span class="monospaced">fun</span> declarations. Polymorphic instantiation is made
43 explicit by specifying type arguments at variable references. <a href="XML">XML</a>
44 patterns can not be nested and can not contain wildcards, constraints,
45 flexible records, or layering.</p></div>
46 </div>
47 </div>
48 <div class="sect1">
49 <h2 id="_implementation">Implementation</h2>
50 <div class="sectionbody">
51 <div class="ulist"><ul>
52 <li>
53 <p>
54 <a href="https://github.com/MLton/mlton/blob/master/mlton/xml/xml.sig"><span class="monospaced">xml.sig</span></a>
55 </p>
56 </li>
57 <li>
58 <p>
59 <a href="https://github.com/MLton/mlton/blob/master/mlton/xml/xml.fun"><span class="monospaced">xml.fun</span></a>
60 </p>
61 </li>
62 <li>
63 <p>
64 <a href="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-tree.sig"><span class="monospaced">xml-tree.sig</span></a>
65 </p>
66 </li>
67 <li>
68 <p>
69 <a href="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-tree.fun"><span class="monospaced">xml-tree.fun</span></a>
70 </p>
71 </li>
72 </ul></div>
73 </div>
74 </div>
75 <div class="sect1">
76 <h2 id="_type_checking">Type Checking</h2>
77 <div class="sectionbody">
78 <div class="paragraph"><p><a href="XML">XML</a> also has a type checker, used for debugging. At present, the
79 type checker is also the best specification of the type system of
80 <a href="XML">XML</a>. If you need more details, the type checker
81 (<a href="https://github.com/MLton/mlton/blob/master/mlton/xml/type-check.sig"><span class="monospaced">type-check.sig</span></a>,
82 <a href="https://github.com/MLton/mlton/blob/master/mlton/xml/type-check.fun"><span class="monospaced">type-check.fun</span></a>), is pretty short.</p></div>
83 <div class="paragraph"><p>Since the type checker does not affect the output of the compiler
84 (unless it reports an error), it can be turned off. The type checker
85 recursively descends the program, checking that the type annotating
86 each node is the same as the type synthesized from the types of the
87 expressions subnodes.</p></div>
88 </div>
89 </div>
90 <div class="sect1">
91 <h2 id="_details_and_notes">Details and Notes</h2>
92 <div class="sectionbody">
93 <div class="paragraph"><p><a href="XML">XML</a> uses the same atoms as <a href="CoreML">CoreML</a>, hence all identifiers
94 (constructors, variables, etc.) are unique and can have properties
95 attached to them. Finally, <a href="XML">XML</a> has a simplifier (<a href="XMLShrink">XMLShrink</a>),
96 which implements a reduction system.</p></div>
97 <div class="sect2">
98 <h3 id="_types">Types</h3>
99 <div class="paragraph"><p><a href="XML">XML</a> types are either type variables or applications of n-ary type
100 constructors. There are many utility functions for constructing and
101 destructing types involving built-in type constructors.</p></div>
102 <div class="paragraph"><p>A type scheme binds list of type variables in a type. The only
103 interesting operation on type schemes is the application of a type
104 scheme to a list of types, which performs a simultaneous substitution
105 of the type arguments for the bound type variables of the scheme. For
106 the purposes of type checking, it is necessary to know the type scheme
107 of variables, constructors, and primitives. This is done by
108 associating the scheme with the identifier using its property list.
109 This approach is used instead of the more traditional environment
110 approach for reasons of speed.</p></div>
111 </div>
112 <div class="sect2">
113 <h3 id="_xmltree">XmlTree</h3>
114 <div class="paragraph"><p>Before defining <span class="monospaced">XML</span>, the signature for language <a href="XML">XML</a>, we need to
115 define an auxiliary signature <span class="monospaced">XML_TREE</span>, that contains the datatype
116 declarations for the expression trees of <a href="XML">XML</a>. This is done solely
117 for the purpose of modularity&#8201;&#8212;&#8201;it allows the simplifier and type
118 checker to be defined by separate functors (which take a structure
119 matching <span class="monospaced">XML_TREE</span>). Then, <span class="monospaced">Xml</span> is defined as the signature for a
120 module containing the expression trees, the simplifier, and the type
121 checker.</p></div>
122 <div class="paragraph"><p>Both constructors and variables can have type schemes, hence both
123 constructor and variable references specify the instance of the scheme
124 at the point of references. An instance is specified with a vector of
125 types, which corresponds to the type variables in the scheme.</p></div>
126 <div class="paragraph"><p><a href="XML">XML</a> patterns are flat (i.e. not nested). A pattern is a
127 constructor with an optional argument variable. Patterns only occur
128 in <span class="monospaced">case</span> expressions. To evaluate a case expression, compare the
129 test value sequentially against each pattern. For the first pattern
130 that matches, destruct the value if necessary to bind the pattern
131 variables and evaluate the corresponding expression. If no pattern
132 matches, evaluate the default. All patterns of a case statement are
133 of the same variant of <span class="monospaced">Pat.t</span>, although this is not enforced by ML&#8217;s
134 type system. The type checker, however, does enforce this. Because
135 tuple patterns are irrefutable, there will only ever be one tuple
136 pattern in a case expression and there will be no default.</p></div>
137 <div class="paragraph"><p><a href="XML">XML</a> contains value, exception, and mutually recursive function
138 declarations. There are no free type variables in <a href="XML">XML</a>. All type
139 variables are explicitly bound at either a value or function
140 declaration. At some point in the future, exception declarations may
141 go away, and exceptions may be represented with a single datatype
142 containing a <span class="monospaced">unit ref</span> component to implement genericity.</p></div>
143 <div class="paragraph"><p><a href="XML">XML</a> expressions are like those of <a href="CoreML">CoreML</a>, with the following
144 exceptions. There are no records expressions. After type inference,
145 all records (some of which may have originally been tuples in the
146 source) are converted to tuples, because once flexible record patterns
147 have been resolved, tuple labels are superfluous. Tuple components
148 are ordered based on the field ordering relation. <a href="XML">XML</a> eta expands
149 primitives and constructors so that there are always fully applied.
150 Hence, the only kind of value of arrow type is a lambda. This
151 property is useful for flow analysis and later in code generation.</p></div>
152 <div class="paragraph"><p>An <a href="XML">XML</a> program is a list of toplevel datatype declarations and a
153 body expression. Because datatype declarations are not generative,
154 the defunctorizer can safely move them to toplevel.</p></div>
155 </div>
156 </div>
157 </div>
158 </div>
159 <div id="footnotes"><hr></div>
160 <div id="footer">
161 <div id="footer-text">
162 </div>
163 <div id="footer-badges">
164 </div>
165 </div>
166 </body>
167 </html>