<!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>ShowBasis</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>ShowBasis</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>MLton has a flag, <span class="monospaced">-show-basis &lt;file&gt;</span>, that causes MLton to pretty
print to <em>file</em> the basis defined by the input program.  For example,
if <span class="monospaced">foo.sml</span> contains</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">fun</span><span class="w"> </span><span class="n">f</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">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="mi">1</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>then <span class="monospaced">mlton -show-basis foo.basis foo.sml</span> will create <span class="monospaced">foo.basis</span>
with the following contents.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>val f: int -&gt; int</pre>
</div></div>
<div class="paragraph"><p>If you only want to see the basis and do not wish to compile the
program, you can call MLton with <span class="monospaced">-stop tc</span>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_displaying_signatures">Displaying signatures</h2>
<div class="sectionbody">
<div class="paragraph"><p>When displaying signatures, MLton prefixes types defined in the
signature them with <span class="monospaced">?.</span> to distinguish them from types defined in the
environment.  For example,</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><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="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="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">unit</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>is displayed as</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>signature SIG =
   sig
      type t = ?.t
      val x: (?.t * int) -&gt; unit
   end</pre>
</div></div>
<div class="paragraph"><p>Notice that <span class="monospaced">int</span> occurs without the <span class="monospaced">?.</span> prefix.</p></div>
<div class="paragraph"><p>MLton also uses a canonical name for each type in the signature, and
that name is used everywhere for that type, no matter what the input
signature looked like.  For example:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><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="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">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">val</span><span class="w"> </span><span class="n">y</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>is displayed as</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>signature SIG =
   sig
      type t = ?.t
      type u = ?.t
      val x: ?.t
      val y: ?.t
   end</pre>
</div></div>
<div class="paragraph"><p>Canonical names are always relative to the "top" of the signature,
even when used in nested substructures.  For example:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><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">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">structure</span><span class="w"> </span><span class="n">U</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">u</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">val</span><span class="w"> </span><span class="n">y</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>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="p">:</span><span class="w"> </span><span class="n">U</span><span class="p">.</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>is displayed as</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>signature S =
   sig
      type t = ?.t
      val w: ?.t
      val z: ?.U.u
      structure U:
         sig
            type u = ?.U.u
            val x: ?.t
            val y: ?.U.u
         end
   end</pre>
</div></div>
</div>
</div>
<div class="sect1">
<h2 id="_displaying_structures">Displaying structures</h2>
<div class="sectionbody">
<div class="paragraph"><p>When displaying structures, MLton uses signature constraints wherever
possible, combined with <span class="monospaced">where type</span> clauses to specify the meanings
of the types defined within the signature.  For example:</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><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="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">structure</span><span class="w"> </span><span class="n">S</span><span class="p">:</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">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">int</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="mi">13</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">S2</span><span class="p">:&gt;</span><span class="w"> </span><span class="n">SIG</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>is displayed as</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>structure S: SIG
             where type t = int
structure S2: SIG
              where type t = S2.t
signature SIG =
   sig
      type t = ?.t
      val x: ?.t
   end</pre>
</div></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>
