<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.10">
<title>SMLNJDeviations</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 20201002</a>
</div>
</div>
<div id="header">
<h1>SMLNJDeviations</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Here are some deviations of <a href="SMLNJ">SML/NJ</a> from
<a href="DefinitionOfStandardML">The Definition of Standard ML (Revised)</a>.
Some of these are documented in the
<a href="http://www.smlnj.org/doc/Conversion/index.html">SML '97 Conversion Guide</a>.
Since MLton does not deviate from the Definition, you should look here
if you are having trouble porting a program from MLton to SML/NJ or
vice versa.  If you discover other deviations of SML/NJ that aren&#8217;t
listed here, please send mail to
<a href="mailto:MLton-devel@mlton.org"><span class="monospaced">MLton-devel@mlton.org</span></a>.</p></div>
<div class="ulist"><ul>
<li>
<p>
SML/NJ allows spaces in long identifiers, as in <span class="monospaced">S . x</span>.  Section
2.5 of the Definition implies that <span class="monospaced">S . x</span> should be treated as three
separate lexical items.
</p>
</li>
<li>
<p>
SML/NJ allows <span class="monospaced">op</span> to appear in <span class="monospaced">val</span> specifications:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">FOO</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">sig</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="k">op</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>The grammar on page 14 of the Definition does not allow it. Recent
versions of SML/NJ do give a warning.</p></div>
</li>
<li>
<p>
SML/NJ rejects
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="p">(</span><span class="k">op</span><span class="w"> </span><span class="n">*</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>as an unmatched close comment.</p></div>
</li>
<li>
<p>
SML/NJ allows <span class="monospaced">=</span> to be rebound by the declaration:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">val</span><span class="w"> </span><span class="k">op</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is explicitly forbidden on page 5 of the Definition. Recent
versions of SML/NJ do give a warning.</p></div>
</li>
<li>
<p>
SML/NJ allows rebinding <span class="monospaced">true</span>, <span class="monospaced">false</span>, <span class="monospaced">nil</span>, <span class="monospaced">::</span>, and <span class="monospaced">ref</span> by
the declarations:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">fun</span><span class="w"> </span><span class="n">true</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="k">fun</span><span class="w"> </span><span class="n">false</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="k">fun</span><span class="w"> </span><span class="n">nil</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="k">fun</span><span class="w"> </span><span class="k">op</span><span class="w"> </span><span class="n">::</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="k">fun</span><span class="w"> </span><span class="n">ref</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is explicitly forbidden on page 9 of the Definition.</p></div>
</li>
<li>
<p>
SML/NJ extends the syntax of the language to allow vector
expressions and patterns like the following:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">val</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">#[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span><span class="w"></span>
<span class="k">val</span><span class="w"> </span><span class="p">#[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">v</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>MLton supports vector expressions and patterns with the <a href="SuccessorML#VectorExpsAndPats"><span class="monospaced">allowVectorExpsAndPats</span></a> <a href="MLBasisAnnotations">ML Basis annotation</a>.</p></div>
</li>
<li>
<p>
SML/NJ extends the syntax of the language to allow <em>or patterns</em>
like the following:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">datatype</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">Bar</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="k">val</span><span class="w"> </span><span class="p">(</span><span class="n">Foo</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">Bar</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>MLton supports or patterns with the <a href="SuccessorML#OrPats"><span class="monospaced">allowOrPats</span></a> <a href="MLBasisAnnotations">ML Basis annotation</a>.</p></div>
</li>
<li>
<p>
SML/NJ allows higher-order functors, that is, functors can be
components of structures and can be passed as functor arguments and
returned as functor results.  As a consequence, SML/NJ allows
abbreviated functor definitions, as in the following:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">    </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"></span>
<span class="k">functor</span><span class="w"> </span><span class="n">F</span><span class="w"> </span><span class="p">(</span><span class="k">structure</span><span class="w"> </span><span class="n">A</span><span class="p">:</span><span class="w"> </span><span class="n">S</span><span class="p">):</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">struct</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">A</span><span class="p">.</span><span class="n">t</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">A</span><span class="p">.</span><span class="n">t</span><span class="w"></span>
<span class="w">    </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">(</span><span class="n">A</span><span class="p">.</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">A</span><span class="p">.</span><span class="n">x</span><span class="p">)</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"></span>
<span class="k">functor</span><span class="w"> </span><span class="n">G</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">F</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ extends the syntax of the language to allow <span class="monospaced">functor</span> and
<span class="monospaced">signature</span> declarations to occur within the scope of <span class="monospaced">local</span> and
<span class="monospaced">structure</span> declarations.
</p>
</li>
<li>
<p>
SML/NJ allows duplicate type specifications in signatures when the
duplicates are introduced by <span class="monospaced">include</span>, as in the following:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">SIG1</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG2</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">v</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">include</span><span class="w"> </span><span class="n">SIG1</span><span class="w"></span>
<span class="w">      </span><span class="k">include</span><span class="w"> </span><span class="n">SIG2</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is disallowed by rule 77 of the Definition.</p></div>
</li>
<li>
<p>
SML/NJ allows sharing constraints between type abbreviations in
signatures, as in the following:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="w">      </span><span class="k">sharing</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>These are disallowed by rule 78 of the Definition.  Recent versions of
SML/NJ correctly disallow sharing constraints between type
abbreviations in signatures.</p></div>
</li>
<li>
<p>
SML/NJ disallows multiple <span class="monospaced">where type</span> specifications of the same
type name, as in the following
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">     </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">     </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"></span>
<span class="w">  </span><span class="k">where</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is allowed by rule 64 of the Definition.</p></div>
</li>
<li>
<p>
SML/NJ allows <span class="monospaced">and</span> in <span class="monospaced">sharing</span> specs in signatures, as in
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="w">      </span><span class="k">type</span><span class="w"> </span><span class="n">v</span><span class="w"></span>
<span class="w">      </span><span class="k">sharing</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="w">      </span><span class="k">and</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">v</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ does not expand the <span class="monospaced">withtype</span> derived form as described by
the Definition.  According to page 55 of the Definition, the type
bindings of a <span class="monospaced">withtype</span> declaration are substituted simultaneously in
the connected datatype.  Consider the following program.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">real</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
<span class="k">datatype</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">  </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="k">withtype</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="k">and</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>According to the Definition, it should be expanded to the following.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">real</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
<span class="k">datatype</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
<span class="w">  </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
<span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="k">and</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">u</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>However, SML/NJ expands <span class="monospaced">withtype</span> bindings sequentially, meaning that
earlier bindings are expanded within later ones. Hence, the above
program is expanded to the following.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">real</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
<span class="k">datatype</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">    </span><span class="n">A</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="w">  </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
<span class="k">type</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ allows <span class="monospaced">withtype</span> specifications in signatures.
</p>
<div class="paragraph"><p>MLton supports <span class="monospaced">withtype</span> specifications in signatures with the <a href="SuccessorML#SigWithtype"><span class="monospaced">allowSigWithtype</span></a> <a href="MLBasisAnnotations">ML Basis annotation</a>.</p></div>
</li>
<li>
<p>
SML/NJ allows a <span class="monospaced">where</span> structure specification that is similar to a
<span class="monospaced">where type</span> specification.  For example:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">     </span><span class="k">structure</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is equivalent to:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">     </span><span class="k">structure</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">T</span><span class="p">.</span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="p">.</span><span class="n">t</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>SML/NJ also allows a definitional structure specification that is
similar to a definitional type specification.  For example:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">     </span><span class="k">structure</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="k">end</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This is equivalent to the previous examples and to:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">  </span><span class="k">sig</span><span class="w"></span>
<span class="w">     </span><span class="k">structure</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="k">end</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="p">.</span><span class="n">t</span><span class="w"></span>
<span class="w">  </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ disallows binding non-datatypes with datatype replication.
For example, it rejects the following program that should be allowed
according to the Definition.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">type</span><span class="w"> </span><span class="p">(</span><span class="n">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">&#39;b</span><span class="p">)</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">&#39;b</span><span class="w"></span>
<span class="k">datatype</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">datatype</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This idiom can be useful when one wants to rename a type without
rewriting all the type arguments.  For example, the above would have
to be written in SML/NJ as follows.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">type</span><span class="w"> </span><span class="p">(</span><span class="n">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">&#39;b</span><span class="p">)</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">&#39;b</span><span class="w"></span>
<span class="k">type</span><span class="w"> </span><span class="p">(</span><span class="n">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">&#39;b</span><span class="p">)</span><span class="w"> </span><span class="n">u</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">(</span><span class="n">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">&#39;b</span><span class="p">)</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ disallows sharing a structure with one of its substructures.
For example, SML/NJ disallows the following.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">signature</span><span class="w"> </span><span class="n">SIG</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="p">:</span><span class="w"></span>
<span class="w">         </span><span class="k">sig</span><span class="w"></span>
<span class="w">            </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
<span class="w">            </span><span class="k">structure</span><span class="w"> </span><span class="n">T</span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="w">         </span><span class="k">end</span><span class="w"></span>
<span class="w">      </span><span class="k">sharing</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="p">.</span><span class="n">T</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>This signature is allowed by the Definition.</p></div>
</li>
<li>
<p>
SML/NJ disallows polymorphic generalization of refutable
patterns. For example, SML/NJ disallows the following.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">val</span><span class="w"> </span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">[[]]</span><span class="w"></span>
<span class="k">val</span><span class="w"> </span><span class="p">_</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="n">::</span><span class="w"> </span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;one&quot;</span><span class="w"> </span><span class="n">::</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>Recent versions of SML/NJ correctly allow polymorphic generalization
of refutable patterns.</p></div>
</li>
<li>
<p>
SML/NJ uses an overly restrictive context for type inference.  For
example, SML/NJ rejects both of the following.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="k">struct</span><span class="w"></span>
<span class="w">  </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="p">[]</span><span class="w"></span>
<span class="w">  </span><span class="k">val</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">::</span><span class="w"> </span><span class="p">[</span><span class="n">true</span><span class="p">]</span><span class="w"> </span><span class="n">::</span><span class="w"> </span><span class="n">nil</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">sig</span><span class="w"> </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">bool</span><span class="w"> </span><span class="n">list</span><span class="w"> </span><span class="k">end</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="k">struct</span><span class="w"></span>
<span class="w">  </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="p">[]</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>These structures are allowed by the Definition.</p></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_deviations_from_the_basis_library_specification">Deviations from the Basis Library Specification</h2>
<div class="sectionbody">
<div class="paragraph"><p>Here are some deviations of SML/NJ from the <a href="BasisLibrary">Basis Library</a>
<a href="http://www.standardml.org/Basis">specification</a>.</p></div>
<div class="ulist"><ul>
<li>
<p>
SML/NJ exposes the equality of the <span class="monospaced">vector</span> type in structures such
as <span class="monospaced">Word8Vector</span> that abstractly match <span class="monospaced">MONO_VECTOR</span>, which says
<span class="monospaced">type vector</span>, not <span class="monospaced">eqtype vector</span>.  So, for example, SML/NJ accepts
the following program:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">fun</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">v</span><span class="p">:</span><span class="w"> </span><span class="n">Word8Vector</span><span class="p">.</span><span class="n">vector</span><span class="p">)</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">v</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
SML/NJ exposes the equality property of the type <span class="monospaced">status</span> in
<span class="monospaced">OS.Process</span>. This means that programs which directly compare two
values of type <span class="monospaced">status</span> will work with SML/NJ but not MLton.
</p>
</li>
<li>
<p>
Under SML/NJ on Windows, <span class="monospaced">OS.Path.validVolume</span> incorrectly considers
absolute empty volumes to be valid. In other words, when the
expression
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="n">OS</span><span class="p">.</span><span class="n">Path</span><span class="p">.</span><span class="n">validVolume</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">isAbs</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">true</span><span class="p">,</span><span class="w"> </span><span class="n">vol</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">&quot;&quot;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>is evaluated by SML/NJ on Windows, the result is <span class="monospaced">true</span>.  MLton, on
the other hand, correctly follows the Basis Library Specification,
which states that on Windows, <span class="monospaced">OS.Path.validVolume</span> should return
<span class="monospaced">false</span> whenever <span class="monospaced">isAbs = true</span> and <span class="monospaced">vol = ""</span>.</p></div>
<div class="paragraph"><p>This incorrect behavior causes other <span class="monospaced">OS.Path</span> functions to behave
differently. For example, when the expression</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="n">OS</span><span class="p">.</span><span class="n">Path</span><span class="p">.</span><span class="n">toString</span><span class="w"> </span><span class="p">(</span><span class="n">OS</span><span class="p">.</span><span class="n">Path</span><span class="p">.</span><span class="n">fromString</span><span class="w"> </span><span class="s">&quot;</span><span class="se">\\</span><span class="s">usr</span><span class="se">\\</span><span class="s">local&quot;</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>is evaluated by SML/NJ on Windows, the result is <span class="monospaced">"\\usr\\local"</span>,
whereas under MLton on Windows, evaluating this expression (correctly)
causes an <span class="monospaced">OS.Path.Path</span> exception to be raised.</p></div>
</li>
</ul></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>
