<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>MLBasisSyntaxAndSemantics</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>MLBasisSyntaxAndSemantics</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>An <a href="MLBasis">ML Basis</a> (MLB) file should have the <span class="monospaced">.mlb</span> suffix and
should contain a basis declaration.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_syntax">Syntax</h2>
<div class="sectionbody">
<div class="paragraph"><p>A basis declaration (<em>basdec</em>) must be one of the following forms.</p></div>
<div class="ulist"><ul>
<li>
<p>
<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>
</p>
</li>
<li>
<p>
<span class="monospaced">open</span> <em>basid<sub>1</sub></em> &#8230; <em>basid<sub>n</sub></em>
</p>
</li>
<li>
<p>
<span class="monospaced">local</span> <em>basdec</em> <span class="monospaced">in</span> <em>basdec</em> <span class="monospaced">end</span>
</p>
</li>
<li>
<p>
<em>basdec</em> [<span class="monospaced">;</span>] <em>basdec</em>
</p>
</li>
<li>
<p>
<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>
</p>
</li>
<li>
<p>
<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>
</p>
</li>
<li>
<p>
<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>
</p>
</li>
<li>
<p>
<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>
</p>
</li>
<li>
<p>
<em>path</em><span class="monospaced">.mlb</span>
</p>
</li>
<li>
<p>
<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>
</p>
</li>
</ul></div>
<div class="paragraph"><p>A basis expression (<em>basexp</em>) must be of one the following forms.</p></div>
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">bas</span> <em>basdec</em> <span class="monospaced">end</span>
</p>
</li>
<li>
<p>
<em>basid</em>
</p>
</li>
<li>
<p>
<span class="monospaced">let</span> <em>basdec</em> <span class="monospaced">in</span> <em>basexp</em> <span class="monospaced">end</span>
</p>
</li>
</ul></div>
<div class="paragraph"><p>Nested SML-style comments (enclosed with <span class="monospaced">(*</span> and <span class="monospaced">*)</span>) are ignored
(but <a href="LineDirective">LineDirective</a>s are recognized).</p></div>
<div class="paragraph"><p>Paths can be relative or absolute.  Relative paths are relative to the
directory containing the MLB file.  Paths may include path variables
and are expanded according to a <a href="MLBasisPathMap">path map</a>.  Unquoted
paths may include alpha-numeric characters and the symbols "<span class="monospaced">-</span>" and
"<span class="monospaced">_</span>", along with the arc separator "<span class="monospaced">/</span>" and extension separator
"<span class="monospaced">.</span>".  More complicated paths, including paths with spaces, may be
included by quoting the path with <span class="monospaced">"</span>.  A quoted path is lexed as an
SML string constant.</p></div>
<div class="paragraph"><p><a href="MLBasisAnnotations">Annotations</a> allow a library author to
control options that affect the elaboration of SML source files.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_semantics">Semantics</h2>
<div class="sectionbody">
<div class="paragraph"><p>There is a <a href="MLBasis.attachments/mlb-formal.pdf">formal semantics</a> for
ML Basis files in the style of the
<a href="DefinitionOfStandardML">Definition</a>.  Here, we give an informal
explanation.</p></div>
<div class="paragraph"><p>An SML structure is a collection of types, values, and other
structures.  Similarly, a basis is a collection, but of more kinds of
objects: types, values, structures, fixities, signatures, functors,
and other bases.</p></div>
<div class="paragraph"><p>A basis declaration denotes a basis.  A structure, signature, or
functor declaration denotes a basis containing the corresponding
module.  Sequencing of basis declarations merges bases, with later
definitions taking precedence over earlier ones, just like sequencing
of SML declarations.  Local declarations provide name hiding, just
like SML local declarations.  A reference to an SML source file causes
the file to be elaborated in the basis extant at the point of
reference.  A reference to an MLB file causes the basis denoted by
that MLB file to be imported&#8201;&#8212;&#8201;the basis at the point of reference
does <em>not</em> affect the imported basis.</p></div>
<div class="paragraph"><p>Basis expressions and basis identifiers allow binding a basis to a
name.</p></div>
<div class="paragraph"><p>An MLB file is elaborated starting in an empty basis.  Each MLB file
is elaborated and evaluated only once, with the result being cached.
Subsequent references use the cached value.  Thus, any observable
effects due to evaluation are not duplicated if the MLB file is
referred to multiple times.</p></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
