<!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>MLtonStructure</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>MLtonStructure</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>The <span class="monospaced">MLton</span> structure contains a lot of functionality that is not
available in the <a href="BasisLibrary">Basis Library</a>.  As a warning,
please keep in mind that the <span class="monospaced">MLton</span> structure and its
substructures do change from release to release of MLton.</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">MLton</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">val</span><span class="w"> </span><span class="n">eq</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;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">equal</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;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">hash</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">Word32</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">isMLton</span><span class="p">:</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">share</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</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">val</span><span class="w"> </span><span class="n">shareAll</span><span class="p">:</span><span class="w"> </span><span class="n">unit</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">val</span><span class="w"> </span><span class="n">size</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">IntInf</span><span class="p">.</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">sizeAll</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">IntInf</span><span class="p">.</span><span class="n">int</span><span class="w"></span>

<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Array</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_ARRAY</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">BinIO</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_BIN_IO</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">CharArray</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_MONO_ARRAY</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">CharArray</span><span class="p">.</span><span class="n">array</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">elem</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">CharArray</span><span class="p">.</span><span class="n">elem</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">CharVector</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_MONO_VECTOR</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">CharVector</span><span class="p">.</span><span class="n">vector</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">elem</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">CharVector</span><span class="p">.</span><span class="n">elem</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Cont</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_CONT</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Exn</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_EXN</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Finalizable</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_FINALIZABLE</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">GC</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_GC</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">IntInf</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_INT_INF</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Itimer</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_ITIMER</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">LargeReal</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_REAL</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">LargeReal</span><span class="p">.</span><span class="n">real</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">LargeWord</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">LargeWord</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Platform</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_PLATFORM</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Pointer</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_POINTER</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">ProcEnv</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_PROC_ENV</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Process</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_PROCESS</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Profile</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_PROFILE</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Random</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_RANDOM</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Real</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_REAL</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">Real</span><span class="p">.</span><span class="n">real</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Real32</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">include</span><span class="w"> </span><span class="n">MLTON_REAL</span><span class="w"></span>
<span class="w">                           </span><span class="k">val</span><span class="w"> </span><span class="n">castFromWord</span><span class="p">:</span><span class="w"> </span><span class="n">Word32</span><span class="p">.</span><span class="n">word</span><span class="w"> </span><span class="p">-&gt;</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">castToWord</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">Word32</span><span class="p">.</span><span class="n">word</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="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Real32</span><span class="p">.</span><span class="n">real</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Real64</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">include</span><span class="w"> </span><span class="n">MLTON_REAL</span><span class="w"></span>
<span class="w">                           </span><span class="k">val</span><span class="w"> </span><span class="n">castFromWord</span><span class="p">:</span><span class="w"> </span><span class="n">Word64</span><span class="p">.</span><span class="n">word</span><span class="w"> </span><span class="p">-&gt;</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">castToWord</span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">Word64</span><span class="p">.</span><span class="n">word</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="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Real64</span><span class="p">.</span><span class="n">real</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Rlimit</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_RLIMIT</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Rusage</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_RUSAGE</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Signal</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_SIGNAL</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Syslog</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_SYSLOG</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">TextIO</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_TEXT_IO</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Thread</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_THREAD</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Vector</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_VECTOR</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Weak</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WEAK</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">Word</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word8</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">Word8</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word16</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">Word16</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word32</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">Word32</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word64</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORD</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">Word64</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word8Array</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_MONO_ARRAY</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">Word8Array</span><span class="p">.</span><span class="n">array</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">elem</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Word8Array</span><span class="p">.</span><span class="n">elem</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">Word8Vector</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_MONO_VECTOR</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">Word8Vector</span><span class="p">.</span><span class="n">vector</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">elem</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Word8Vector</span><span class="p">.</span><span class="n">elem</span><span class="w"></span>
<span class="w">      </span><span class="k">structure</span><span class="w"> </span><span class="n">World</span><span class="p">:</span><span class="w"> </span><span class="n">MLTON_WORLD</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</div>
</div>
<div class="sect1">
<h2 id="_substructures">Substructures</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<a href="MLtonArray">MLtonArray</a>
</p>
</li>
<li>
<p>
<a href="MLtonBinIO">MLtonBinIO</a>
</p>
</li>
<li>
<p>
<a href="MLtonCont">MLtonCont</a>
</p>
</li>
<li>
<p>
<a href="MLtonExn">MLtonExn</a>
</p>
</li>
<li>
<p>
<a href="MLtonFinalizable">MLtonFinalizable</a>
</p>
</li>
<li>
<p>
<a href="MLtonGC">MLtonGC</a>
</p>
</li>
<li>
<p>
<a href="MLtonIntInf">MLtonIntInf</a>
</p>
</li>
<li>
<p>
<a href="MLtonIO">MLtonIO</a>
</p>
</li>
<li>
<p>
<a href="MLtonItimer">MLtonItimer</a>
</p>
</li>
<li>
<p>
<a href="MLtonMonoArray">MLtonMonoArray</a>
</p>
</li>
<li>
<p>
<a href="MLtonMonoVector">MLtonMonoVector</a>
</p>
</li>
<li>
<p>
<a href="MLtonPlatform">MLtonPlatform</a>
</p>
</li>
<li>
<p>
<a href="MLtonPointer">MLtonPointer</a>
</p>
</li>
<li>
<p>
<a href="MLtonProcEnv">MLtonProcEnv</a>
</p>
</li>
<li>
<p>
<a href="MLtonProcess">MLtonProcess</a>
</p>
</li>
<li>
<p>
<a href="MLtonRandom">MLtonRandom</a>
</p>
</li>
<li>
<p>
<a href="MLtonReal">MLtonReal</a>
</p>
</li>
<li>
<p>
<a href="MLtonRlimit">MLtonRlimit</a>
</p>
</li>
<li>
<p>
<a href="MLtonRusage">MLtonRusage</a>
</p>
</li>
<li>
<p>
<a href="MLtonSignal">MLtonSignal</a>
</p>
</li>
<li>
<p>
<a href="MLtonSyslog">MLtonSyslog</a>
</p>
</li>
<li>
<p>
<a href="MLtonTextIO">MLtonTextIO</a>
</p>
</li>
<li>
<p>
<a href="MLtonThread">MLtonThread</a>
</p>
</li>
<li>
<p>
<a href="MLtonVector">MLtonVector</a>
</p>
</li>
<li>
<p>
<a href="MLtonWeak">MLtonWeak</a>
</p>
</li>
<li>
<p>
<a href="MLtonWord">MLtonWord</a>
</p>
</li>
<li>
<p>
<a href="MLtonWorld">MLtonWorld</a>
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_values">Values</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<span class="monospaced">eq (x, y)</span>
</p>
<div class="paragraph"><p>returns true if <span class="monospaced">x</span> and <span class="monospaced">y</span> are equal as pointers.  For simple types
like <span class="monospaced">char</span>, <span class="monospaced">int</span>, and <span class="monospaced">word</span>, this is the same as equals.  For
arrays, datatypes, strings, tuples, and vectors, this is a simple
pointer equality.  The semantics is a bit murky.</p></div>
</li>
<li>
<p>
<span class="monospaced">equal (x, y)</span>
</p>
<div class="paragraph"><p>returns true if <span class="monospaced">x</span> and <span class="monospaced">y</span> are structurally equal.  For equality
types, this is the same as <a href="PolymorphicEquality">PolymorphicEquality</a>.  For other types,
it is a conservative approximation of equivalence.</p></div>
</li>
<li>
<p>
<span class="monospaced">hash x</span>
</p>
<div class="paragraph"><p>returns a structural hash of <span class="monospaced">x</span>.  The hash function is consistent
between execution of the same program, but may not be consistent
between different programs.</p></div>
</li>
<li>
<p>
<span class="monospaced">isMLton</span>
</p>
<div class="paragraph"><p>is always <span class="monospaced">true</span> in a MLton implementation, and is always <span class="monospaced">false</span> in a
stub implementation.</p></div>
</li>
<li>
<p>
<span class="monospaced">share x</span>
</p>
<div class="paragraph"><p>maximizes sharing in the heap for the object graph reachable from <span class="monospaced">x</span>.</p></div>
</li>
<li>
<p>
<span class="monospaced">shareAll ()</span>
</p>
<div class="paragraph"><p>maximizes sharing in the heap by sharing space for equivalent
immutable objects.  A call to <span class="monospaced">shareAll</span> performs a major garbage
collection, and takes time proportional to the size of the heap.</p></div>
</li>
<li>
<p>
<span class="monospaced">size x</span>
</p>
<div class="paragraph"><p>returns the amount of heap space (in bytes) taken by the value of <span class="monospaced">x</span>,
including all objects reachable from <span class="monospaced">x</span> by following pointers.  It
takes time proportional to the size of <span class="monospaced">x</span>.  See below for an example.</p></div>
</li>
<li>
<p>
<span class="monospaced">sizeAll ()</span>
</p>
<div class="paragraph"><p>returns the amount of heap space (in bytes) taken by all reachable
live data.  It takes time proportional to the size of live data.</p></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_a_id_size_a_example_of_span_class_monospaced_mlton_size_span"><a id="size"></a>Example of <span class="monospaced">MLton.size</span></h2>
<div class="sectionbody">
<div class="paragraph"><p>This example, <span class="monospaced">size.sml</span>, demonstrates the application of <span class="monospaced">MLton.size</span>
to many different kinds of objects.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span></span><span class="k">fun</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="n">name</span><span class="p">:</span><span class="w"> </span><span class="n">string</span><span class="p">,</span><span class="w"> </span><span class="n">value</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">use</span><span class="p">:</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">unit</span><span class="p">):</span><span class="w"> </span><span class="n">unit</span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="p">(</span><span class="n">print</span><span class="w"> </span><span class="s">&quot;The size of &quot;</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="n">name</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="s">&quot; is &quot;</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="p">(</span><span class="n">IntInf</span><span class="p">.</span><span class="n">toString</span><span class="w"> </span><span class="p">(</span><span class="n">MLton</span><span class="p">.</span><span class="n">size</span><span class="w"> </span><span class="n">value</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="s">&quot; bytes.</span><span class="se">\n</span><span class="s">&quot;</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">use</span><span class="w"> </span><span class="n">value</span><span class="p">)</span><span class="w"></span>

<span class="k">fun</span><span class="w"> </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">if</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">y</span><span class="w"></span>
<span class="w">      </span><span class="k">then</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="w">      </span><span class="k">else</span><span class="w"> </span><span class="k">raise</span><span class="w"> </span><span class="n">Fail</span><span class="w"> </span><span class="s">&quot;bug&quot;</span><span class="w"></span>

<span class="k">val</span><span class="w"> </span><span class="n">l</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="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">4</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="w">   </span><span class="p">(</span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;a char&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">#</span><span class="s">&quot;c&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="p">_</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">())</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;an int list of length 4&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="n">List</span><span class="p">.</span><span class="n">tabulate</span><span class="w"> </span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">l</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                 </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">foldl</span><span class="w"> </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><span class="mi">0</span><span class="w"> </span><span class="n">l</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;a string of length 10&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="n">CharVector</span><span class="p">.</span><span class="n">tabulate</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">chr</span><span class="w"> </span><span class="p">(</span><span class="n">ord</span><span class="w"> </span><span class="p">#</span><span class="s">&quot;0&quot;</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">i</span><span class="p">)),</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                 </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">CharVector</span><span class="p">.</span><span class="n">foldl</span><span class="w"> </span><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="p">(</span><span class="n">c</span><span class="p">,</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">ord</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="n">s</span><span class="p">,</span><span class="w">  </span><span class="mi">525</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;an int array of length 10&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="n">Array</span><span class="p">.</span><span class="n">tabulate</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">i</span><span class="p">),</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                 </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">Array</span><span class="p">.</span><span class="n">foldl</span><span class="w"> </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><span class="mi">0</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="mi">45</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;a double array of length 10&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="n">Array</span><span class="p">.</span><span class="n">tabulate</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">real</span><span class="p">),</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                 </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">Real</span><span class="p">.</span><span class="n">floor</span><span class="w"> </span><span class="p">(</span><span class="n">Array</span><span class="p">.</span><span class="n">foldl</span><span class="w"> </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><span class="mf">0.0</span><span class="w"> </span><span class="n">a</span><span class="p">),</span><span class="w"> </span><span class="mi">45</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;an array of length 10 of 2-ples of ints&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="n">Array</span><span class="p">.</span><span class="n">tabulate</span><span class="w"> </span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="mi">1</span><span class="p">)),</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                 </span><span class="n">chk</span><span class="w"> </span><span class="p">(</span><span class="n">Array</span><span class="p">.</span><span class="n">foldl</span><span class="w"> </span><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="p">((</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">),</span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="mi">100</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">;</span><span class="w"> </span><span class="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;a useless function&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                 </span><span class="k">fn</span><span class="w"> </span><span class="p">_</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="mi">13</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">())</span><span class="w"></span>
<span class="w">    </span><span class="p">)</span><span class="w"></span>

<span class="k">local</span><span class="w"></span>
<span class="w">   </span><span class="k">open</span><span class="w"> </span><span class="n">MLton</span><span class="p">.</span><span class="n">Cont</span><span class="w"></span>
<span class="k">in</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">rc</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">option</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="n">option</span><span class="w"> </span><span class="n">ref</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">ref</span><span class="w"> </span><span class="n">NONE</span><span class="w"></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="w">      </span><span class="k">case</span><span class="w"> </span><span class="n">callcc</span><span class="w"> </span><span class="p">(</span><span class="k">fn</span><span class="w"> </span><span class="n">k</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">option</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">rc</span><span class="w"> </span><span class="n">:=</span><span class="w"> </span><span class="n">SOME</span><span class="w"> </span><span class="n">k</span><span class="p">;</span><span class="w"> </span><span class="n">throw</span><span class="w"> </span><span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="w"> </span><span class="n">NONE</span><span class="p">)))</span><span class="w"> </span><span class="k">of</span><span class="w"></span>
<span class="w">         </span><span class="n">NONE</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="w">       </span><span class="p">|</span><span class="w"> </span><span class="n">SOME</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="p">(</span><span class="n">concat</span><span class="w"> </span><span class="p">[</span><span class="n">Int</span><span class="p">.</span><span class="n">toString</span><span class="w"> </span><span class="n">i</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">])</span><span class="w"></span>
<span class="k">end</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="n">printSize</span><span class="w"> </span><span class="p">(</span><span class="s">&quot;a continuation option ref&quot;</span><span class="p">,</span><span class="w"></span>
<span class="w">                   </span><span class="n">rc</span><span class="p">,</span><span class="w"> </span><span class="k">fn</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"></span>
<span class="w">                   </span><span class="k">case</span><span class="w"> </span><span class="n">!rc</span><span class="w"> </span><span class="k">of</span><span class="w"></span>
<span class="w">                      </span><span class="n">NONE</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="w">                    </span><span class="p">|</span><span class="w"> </span><span class="n">SOME</span><span class="w"> </span><span class="n">k</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">rc</span><span class="w"> </span><span class="n">:=</span><span class="w"> </span><span class="n">NONE</span><span class="p">;</span><span class="w"> </span><span class="n">MLton</span><span class="p">.</span><span class="n">Cont</span><span class="p">.</span><span class="n">throw</span><span class="w"> </span><span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="w"> </span><span class="n">SOME</span><span class="w"> </span><span class="mi">13</span><span class="p">)))</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>Compile and run as usual.</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>% mlton size.sml
% ./size
The size of a char is 0 bytes.
The size of an int list of length 4 is 96 bytes.
The size of a string of length 10 is 40 bytes.
The size of an int array of length 10 is 64 bytes.
The size of a double array of length 10 is 104 bytes.
The size of an array of length 10 of 2-ples of ints is 104 bytes.
The size of a useless function is 0 bytes.
The size of a continuation option ref is 5016 bytes.
13
The size of a continuation option ref is 16 bytes.</pre>
</div></div>
<div class="paragraph"><p>Note that sizes are dependent upon the target platform and compiler
optimizations.</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>
