<!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>ShowBasis - 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"> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-833377-1"; urchinTracker(); </script> <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 MLTONWIKIVERSION</a> <td style = " border: 0px; font-size: 150%; text-align: center; width: 50%;"> ShowBasis <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> <a href = "TitleIndex">Index</a> </table> <div id="content" lang="en" dir="ltr"> MLton has a flag, <tt>-show-basis </tt> <em>file</em>, that causes MLton to pretty print to <em>file</em> the basis defined by the input program. For example, if <tt>foo.sml</tt> contains <pre class=code> <B><FONT COLOR="#A020F0">fun</FONT></B> f x = x + <B><FONT COLOR="#5F9EA0">1</FONT></B> </PRE> <p> then <tt>mlton -show-basis foo.basis foo.sml</tt> will create <tt>foo.basis</tt> with the following contents. <pre>val f: int -> int </pre>If you only want to see the basis and do not wish to compile the program, you can call MLton with <tt>-stop tc</tt>. </p> <h2 id="head-f68fa1f6c99a6935aec560696799f2414d893d6f">Displaying signatures</h2> <p> When displaying signatures, MLton prefixes types defined in the signature them with <tt>?.</tt> to distinguish them from types defined in the environment. For example, <pre class=code> <B><FONT COLOR="#0000FF">signature</FONT></B> SIG = <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> x: t * int -> unit <B><FONT COLOR="#0000FF">end</FONT></B> </PRE> is displayed as <pre>signature SIG = sig type t = ?.t val x: (?.t * int) -> unit end </pre>Notice that <tt>int</tt> occurs without the <tt>?.</tt> prefix. </p> <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: <pre class=code> <B><FONT COLOR="#0000FF">signature</FONT></B> SIG = <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> u </FONT></B>=<B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> x: t <B><FONT COLOR="#A020F0">val</FONT></B> y: u <B><FONT COLOR="#0000FF">end</FONT></B> </PRE> is displayed as <pre>signature SIG = sig type t = ?.t type u = ?.t val x: ?.t val y: ?.t end </pre> </p> <p> Canonical names are always relative to the "top" of the signature, even when used in nested substructures. For example: <pre class=code> <B><FONT COLOR="#0000FF">signature</FONT></B> S = <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> w: t <B><FONT COLOR="#0000FF">structure</FONT></B> U: <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> u </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> x: t <B><FONT COLOR="#A020F0">val</FONT></B> y: u <B><FONT COLOR="#0000FF">end</FONT></B> <B><FONT COLOR="#A020F0">val</FONT></B> z: U.u <B><FONT COLOR="#0000FF">end</FONT></B> </PRE> is displayed as <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> </p> <h2 id="head-c6c2aa845cc7b36e66f2c4aa799b976c96116919">Displaying structures</h2> <p> When displaying structures, MLton uses signature constraints wherever possible, combined with <tt>where type</tt> clauses to specify the meanings of the types defined within the signature. </p> <pre class=code> <B><FONT COLOR="#0000FF">signature</FONT></B> SIG = <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> x: t <B><FONT COLOR="#0000FF">end</FONT></B> <B><FONT COLOR="#0000FF">structure</FONT></B> S: SIG = <B><FONT COLOR="#0000FF">struct</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B>=<B><FONT COLOR="#228B22"> int </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> x = <B><FONT COLOR="#5F9EA0">13</FONT></B> <B><FONT COLOR="#0000FF">end</FONT></B> <B><FONT COLOR="#0000FF">structure</FONT></B> S2:> SIG = S </PRE> <p> is displayed as <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> </p> </div> <p> <hr> Last edited on 2005-12-02 01:48:03 by <span title="ppp-71-139-183-221.dsl.snfc21.pacbell.net"><a href="StephenWeeks">StephenWeeks</a></span>. </body></html>