<!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>WarnUnusedAnomalies</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>WarnUnusedAnomalies</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>The <span class="monospaced">warnUnused</span> <a href="MLBasisAnnotations">MLBasis annotation</a> can be used
to report unused identifiers.  This can be useful for catching bugs
and for code maintenance (e.g., eliminating dead code).  However, the
<span class="monospaced">warnUnused</span> annotation can sometimes behave in counter-intuitive
ways.  This page gives some of the anomalies that have been reported.</p></div>
<div class="ulist"><ul>
<li>
<p>
Functions whose only uses are recursive uses within their bodies are
not warned as unused:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">local</span><span class="w"></span>
<span class="k">fun</span><span class="w"> </span><span class="n">foo</span><span class="w"> </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="p">()</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">unit</span><span class="w"></span>
<span class="k">val</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="k">let</span><span class="w"> </span><span class="k">fun</span><span class="w"> </span><span class="n">baz</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">baz</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">unit</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">baz</span><span class="w"> </span><span class="k">end</span><span class="w"></span>
<span class="k">in</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Warning: z.sml 3.5.
  Unused variable: bar.</pre>
</div></div>
</li>
<li>
<p>
Components of actual functor argument that are necessary to match
the functor argument signature but are unused in the body of the
functor are warned as unused:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">functor</span><span class="w"> </span><span class="n">Warning</span><span class="w"> </span><span class="p">(</span><span class="k">type</span><span class="w"> </span><span class="n">t</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="n">t</span><span class="p">)</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">y</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">x</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">X</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Warning</span><span class="w"> </span><span class="p">(</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">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">1</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
<div class="listingblock">
<div class="content monospaced">
<pre>Warning: z.sml 4.29.
  Unused type: t.</pre>
</div></div>
</li>
<li>
<p>
No component of a functor result is warned as unused.  In the
following, the only uses of <span class="monospaced">f2</span> are to match the functor argument
signatures of <span class="monospaced">functor G</span> and <span class="monospaced">functor H</span> and there are no uses of
<span class="monospaced">z</span>:
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">functor</span><span class="w"> </span><span class="n">F</span><span class="p">(</span><span class="k">structure</span><span class="w"> </span><span class="n">X</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="p">)</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">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">X</span><span class="p">.</span><span class="n">t</span><span class="w"></span>
<span class="w">   </span><span class="k">fun</span><span class="w"> </span><span class="n">f1</span><span class="w"> </span><span class="p">(_</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">X</span><span class="p">.</span><span class="n">t</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="w">   </span><span class="k">fun</span><span class="w"> </span><span class="n">f2</span><span class="w"> </span><span class="p">(_</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">X</span><span class="p">.</span><span class="n">t</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="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="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="p">(</span><span class="k">structure</span><span class="w"> </span><span class="n">Y</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">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">f1</span><span class="w"> </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">unit</span><span class="w"></span>
<span class="w">                           </span><span class="k">val</span><span class="w"> </span><span class="n">f2</span><span class="w"> </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">unit</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="n">unit</span><span class="w"></span>
<span class="w">                        </span><span class="k">end</span><span class="p">)</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">fun</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="p">(</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="p">.</span><span class="n">t</span><span class="p">)</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Y</span><span class="p">.</span><span class="n">f1</span><span class="w"> </span><span class="n">x</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">H</span><span class="p">(</span><span class="k">structure</span><span class="w"> </span><span class="n">Y</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">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">f1</span><span class="w"> </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">unit</span><span class="w"></span>
<span class="w">                           </span><span class="k">val</span><span class="w"> </span><span class="n">f2</span><span class="w"> </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">unit</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="n">unit</span><span class="w"></span>
<span class="w">                        </span><span class="k">end</span><span class="p">)</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">fun</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="p">(</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="p">.</span><span class="n">t</span><span class="p">)</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Y</span><span class="p">.</span><span class="n">f1</span><span class="w"> </span><span class="n">x</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">Z</span><span class="p">()</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">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="n">F</span><span class="p">(</span><span class="k">structure</span><span class="w"> </span><span class="n">X</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">unit</span><span class="w"> </span><span class="k">end</span><span class="p">)</span><span class="w"></span>
<span class="w">   </span><span class="k">structure</span><span class="w"> </span><span class="n">SG</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">G</span><span class="p">(</span><span class="k">structure</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">S</span><span class="p">)</span><span class="w"></span>
<span class="w">   </span><span class="k">structure</span><span class="w"> </span><span class="n">SH</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">H</span><span class="p">(</span><span class="k">structure</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">S</span><span class="p">)</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">U</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Z</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="n">U</span><span class="p">.</span><span class="n">SG</span><span class="p">.</span><span class="n">g</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="n">U</span><span class="p">.</span><span class="n">SH</span><span class="p">.</span><span class="n">h</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
</pre></div></div></div>
<div class="listingblock">
<div class="content monospaced">
<pre></pre>
</div></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>
