<!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>LambdaFree</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>LambdaFree</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><a href="LambdaFree">LambdaFree</a> is an analysis pass for the <a href="SXML">SXML</a>
<a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="ClosureConvert">ClosureConvert</a>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph"><p>This pass descends the entire <a href="SXML">SXML</a> program and attaches a property
to each <span class="monospaced">Lambda</span> <span class="monospaced">PrimExp.t</span> in the program.  Then, you can use
<span class="monospaced">lambdaFree</span> and <span class="monospaced">lambdaRec</span> to get free variables of that <span class="monospaced">Lambda</span>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_implementation">Implementation</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig"><span class="monospaced">lambda-free.sig</span></a>
</p>
</li>
<li>
<p>
<a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun"><span class="monospaced">lambda-free.fun</span></a>
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_details_and_notes">Details and Notes</h2>
<div class="sectionbody">
<div class="paragraph"><p>For <span class="monospaced">Lambda</span>-s bound in a <span class="monospaced">Fun</span> dec, <span class="monospaced">lambdaFree</span> gives the union of
the frees of the entire group of mutually recursive functions.  Hence,
<span class="monospaced">lambdaFree</span> for every <span class="monospaced">Lambda</span> in a single <span class="monospaced">Fun</span> dec is the same.
Furthermore, for a <span class="monospaced">Lambda</span> bound in a <span class="monospaced">Fun</span> dec, <span class="monospaced">lambdaRec</span> gives
the list of other functions bound in the same dec defining that
<span class="monospaced">Lambda</span>.</p></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content monospaced">
<pre>val rec f = fn x =&gt; ... y ... g ... f ...
and g = fn z =&gt; ... f ... w ...</pre>
</div></div>
<div class="listingblock">
<div class="content monospaced">
<pre>lambdaFree(fn x =&gt;) = [y, w]
lambdaFree(fn z =&gt;) = [y, w]
lambdaRec(fn x =&gt;) = [g, f]
lambdaRec(fn z =&gt;) = [f]</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>
