Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / MLBasisSyntaxAndSemantics
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>MLBasisSyntaxAndSemantics</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>MLBasisSyntaxAndSemantics</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p>An <a href="MLBasis">ML Basis</a> (MLB) file should have the <span class="monospaced">.mlb</span> suffix and
32 should contain a basis declaration.</p></div>
33 </div>
34 </div>
35 <div class="sect1">
36 <h2 id="_syntax">Syntax</h2>
37 <div class="sectionbody">
38 <div class="paragraph"><p>A basis declaration (<em>basdec</em>) must be one of the following forms.</p></div>
39 <div class="ulist"><ul>
40 <li>
41 <p>
42 <span class="monospaced">basis</span> <em>basid</em> <span class="monospaced">=</span> <em>basexp</em> (<span class="monospaced">and</span> <em>basid</em> <span class="monospaced">=</span> <em>basexp</em>)<sup>*</sup>
43 </p>
44 </li>
45 <li>
46 <p>
47 <span class="monospaced">open</span> <em>basid<sub>1</sub></em> &#8230; <em>basid<sub>n</sub></em>
48 </p>
49 </li>
50 <li>
51 <p>
52 <span class="monospaced">local</span> <em>basdec</em> <span class="monospaced">in</span> <em>basdec</em> <span class="monospaced">end</span>
53 </p>
54 </li>
55 <li>
56 <p>
57 <em>basdec</em> [<span class="monospaced">;</span>] <em>basdec</em>
58 </p>
59 </li>
60 <li>
61 <p>
62 <span class="monospaced">structure</span> <em>strid</em> [<span class="monospaced">=</span> <em>strid</em>] (<span class="monospaced">and</span> <em>strid</em>[<span class="monospaced">=</span> <em>strid</em>])<sup>*</sup>
63 </p>
64 </li>
65 <li>
66 <p>
67 <span class="monospaced">signature</span> <em>sigid</em> [<span class="monospaced">=</span> <em>sigid</em>] (<span class="monospaced">and</span> <em>sigid</em> [<span class="monospaced">=</span> <em>sigid</em>])<sup>*</sup>
68 </p>
69 </li>
70 <li>
71 <p>
72 <span class="monospaced">functor</span> <em>funid</em> [<span class="monospaced">=</span> <em>funid</em>] (<span class="monospaced">and</span> <em>funid</em> [<span class="monospaced">=</span> <em>funid</em>])<sup>*</sup>
73 </p>
74 </li>
75 <li>
76 <p>
77 <em>path</em><span class="monospaced">.sml</span>, <em>path</em><span class="monospaced">.sig</span>, or <em>path</em><span class="monospaced">.fun</span>
78 </p>
79 </li>
80 <li>
81 <p>
82 <em>path</em><span class="monospaced">.mlb</span>
83 </p>
84 </li>
85 <li>
86 <p>
87 <span class="monospaced">ann</span> <span class="monospaced">"</span><em>ann</em><span class="monospaced">"</span> <span class="monospaced">in</span> <em>basdec</em> <span class="monospaced">end</span>
88 </p>
89 </li>
90 </ul></div>
91 <div class="paragraph"><p>A basis expression (<em>basexp</em>) must be of one the following forms.</p></div>
92 <div class="ulist"><ul>
93 <li>
94 <p>
95 <span class="monospaced">bas</span> <em>basdec</em> <span class="monospaced">end</span>
96 </p>
97 </li>
98 <li>
99 <p>
100 <em>basid</em>
101 </p>
102 </li>
103 <li>
104 <p>
105 <span class="monospaced">let</span> <em>basdec</em> <span class="monospaced">in</span> <em>basexp</em> <span class="monospaced">end</span>
106 </p>
107 </li>
108 </ul></div>
109 <div class="paragraph"><p>Nested SML-style comments (enclosed with <span class="monospaced">(*</span> and <span class="monospaced">*)</span>) are ignored
110 (but <a href="LineDirective">LineDirective</a>s are recognized).</p></div>
111 <div class="paragraph"><p>Paths can be relative or absolute. Relative paths are relative to the
112 directory containing the MLB file. Paths may include path variables
113 and are expanded according to a <a href="MLBasisPathMap">path map</a>. Unquoted
114 paths may include alpha-numeric characters and the symbols "<span class="monospaced">-</span>" and
115 "<span class="monospaced">_</span>", along with the arc separator "<span class="monospaced">/</span>" and extension separator
116 "<span class="monospaced">.</span>". More complicated paths, including paths with spaces, may be
117 included by quoting the path with <span class="monospaced">"</span>. A quoted path is lexed as an
118 SML string constant.</p></div>
119 <div class="paragraph"><p><a href="MLBasisAnnotations">Annotations</a> allow a library author to
120 control options that affect the elaboration of SML source files.</p></div>
121 </div>
122 </div>
123 <div class="sect1">
124 <h2 id="_semantics">Semantics</h2>
125 <div class="sectionbody">
126 <div class="paragraph"><p>There is a <a href="MLBasis.attachments/mlb-formal.pdf">formal semantics</a> for
127 ML Basis files in the style of the
128 <a href="DefinitionOfStandardML">Definition</a>. Here, we give an informal
129 explanation.</p></div>
130 <div class="paragraph"><p>An SML structure is a collection of types, values, and other
131 structures. Similarly, a basis is a collection, but of more kinds of
132 objects: types, values, structures, fixities, signatures, functors,
133 and other bases.</p></div>
134 <div class="paragraph"><p>A basis declaration denotes a basis. A structure, signature, or
135 functor declaration denotes a basis containing the corresponding
136 module. Sequencing of basis declarations merges bases, with later
137 definitions taking precedence over earlier ones, just like sequencing
138 of SML declarations. Local declarations provide name hiding, just
139 like SML local declarations. A reference to an SML source file causes
140 the file to be elaborated in the basis extant at the point of
141 reference. A reference to an MLB file causes the basis denoted by
142 that MLB file to be imported&#8201;&#8212;&#8201;the basis at the point of reference
143 does <em>not</em> affect the imported basis.</p></div>
144 <div class="paragraph"><p>Basis expressions and basis identifiers allow binding a basis to a
145 name.</p></div>
146 <div class="paragraph"><p>An MLB file is elaborated starting in an empty basis. Each MLB file
147 is elaborated and evaluated only once, with the result being cached.
148 Subsequent references use the cached value. Thus, any observable
149 effects due to evaluation are not duplicated if the MLB file is
150 referred to multiple times.</p></div>
151 </div>
152 </div>
153 </div>
154 <div id="footnotes"><hr></div>
155 <div id="footer">
156 <div id="footer-text">
157 </div>
158 <div id="footer-badges">
159 </div>
160 </div>
161 </body>
162 </html>