<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



<title>MLBasisSyntaxAndSemantics - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">


<link rel="Start" href="Home">


</head>

<body lang="en" dir="ltr">

<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton 20051202</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      MLBasisSyntaxAndSemantics
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
An <a href="MLBasis">ML Basis</a> (MLB) file should have the <tt>.mlb</tt> suffix and should contain a basis declaration. <h2 id="head-17c7ba7676ad1ad6dd1c4e6b997adcae910262c9">Syntax</h2>
<p>
A basis declaration must be one of the following forms. 
</p>

    <ul>

    <li>
<p>
 <tt>basis&nbsp;</tt><em>basid<tt>&nbsp;=&nbsp;</tt>basexp</em>  (<tt>and&nbsp;</tt><em>basid</em><tt>&nbsp;=&nbsp;</tt><em>basexp</em>)* 
</p>
</li>
    <li>
<p>
 <tt>open&nbsp;</tt><em>basid<sub>1</sub></em> ... <em>basid<sub>n</sub></em> 
</p>
</li>
    <li>
<p>
 <tt>local&nbsp;</tt><em>basdec</em><tt>&nbsp;in&nbsp;</tt><em>basdec</em><tt>&nbsp;end</tt> 
</p>
</li>
    <li>
<p>
 <em>basdec</em> [<tt>;</tt>] <em>basdec</em> 
</p>
</li>
    <li>
<p>
 <tt>structure&nbsp;</tt><em>strid</em> [<tt>=&nbsp;</tt><em>strid</em>]  (<tt>and&nbsp;</tt><em>strid</em>[<tt>=&nbsp;</tt><em>strid</em>])* 
</p>
</li>
    <li>
<p>
 <tt>signature&nbsp;</tt><em>sigid</em> [<tt>=&nbsp;</tt><em>sigid</em>]  (<tt>and&nbsp;</tt><em>sigid</em> [<tt>=&nbsp;</tt><em>sigid</em>])* 
</p>
</li>
    <li>
<p>
 <tt>functor&nbsp;</tt><em>funid</em> [<tt>=&nbsp;</tt><em>funid</em>]  (<tt>and&nbsp;</tt><em>funid</em> [<tt>=&nbsp;</tt><em>funid</em>])* 
</p>
</li>
    <li>
<p>
 <em>path</em><tt>.sml</tt>, <em>path</em><tt>.sig</tt>, or <em>path</em><tt>.fun</tt> 
</p>
</li>
    <li>
<p>
 <em>path</em><tt>.mlb</tt> 
</p>
</li>
    <li>
<p>
 <tt>ann&nbsp;</tt><tt>"</tt><em>ann</em><tt>"</tt><tt>&nbsp;in&nbsp;</tt><em>basdec</em><tt>&nbsp;end</tt> 
</p>
</li>

    </ul>


<p>
A basis expression <em>basexp</em> must be of one the following forms. 
</p>

    <ul>

    <li>
<p>
 <tt>bas&nbsp;</tt><em>basdec</em><tt>&nbsp;end</tt> 
</p>
</li>
    <li>
<p>
 <em>basid</em> 
</p>
</li>
    <li>
<p>
 <tt>let&nbsp;</tt><em>basdec</em><tt>&nbsp;in&nbsp;</tt><em>basexp</em><tt>&nbsp;end</tt> 
</p>
</li>

    </ul>


<p>
Nested SML-style comments (enclosed with <tt>(*</tt> and <tt>*)</tt>) are ignored (but <a href="LineDirective">LineDirective</a>s are recognized). 
</p>
<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 "<tt>-</tt>" and "<tt>_</tt>", along with the arc separator "<tt>/</tt>" and extension separator "<tt>.</tt>".  More complicated paths, including paths with spaces, may be included by quoting the path with <tt>"</tt>.  A quoted path is lexed as a SML string constant. 
</p>
<p>
<a href="MLBasisAnnotations">Annotations</a> allow a library author to control options that affect the elaboration of SML source files. 
</p>
<h2 id="head-fe03c3515833357d89e7094df960e757cae3bc1d">Semantics</h2>
<p>
There is a <a href="http://mlton.org/pages/MLBasis/attachments/mlb-formal.pdf"><img src="moin-www.png" alt="[WWW]" height="11" width="11">formal semantics</a> for ML Basis files in the style of the <a href="DefinitionOfStandardML">Definition</a>. Here, we give an informal explanation. 
</p>
<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>
<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 -- the basis at the point of reference does <em>not</em> affect the imported basis. 
</p>
<p>
Basis expressions and basis identifiers allow binding a basis to a name. 
</p>
<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>



<p>
<hr>
Last edited on 2005-12-01 20:54:18 by <span title="ppp-71-139-183-221.dsl.snfc21.pacbell.net"><a href="StephenWeeks">StephenWeeks</a></span>.
</body></html>
