4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>LambdaFree</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
19 <body class="article">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="LambdaFree">LambdaFree</a> is an analysis pass for the <a href="SXML">SXML</a>
32 <a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="ClosureConvert">ClosureConvert</a>.</p></div>
36 <h2 id="_description">Description</h2>
37 <div class="sectionbody">
38 <div class="paragraph"><p>This pass descends the entire <a href="SXML">SXML</a> program and attaches a property
39 to each <span class="monospaced">Lambda</span> <span class="monospaced">PrimExp.t</span> in the program. Then, you can use
40 <span class="monospaced">lambdaFree</span> and <span class="monospaced">lambdaRec</span> to get free variables of that <span class="monospaced">Lambda</span>.</p></div>
44 <h2 id="_implementation">Implementation</h2>
45 <div class="sectionbody">
46 <div class="ulist"><ul>
49 <a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig"><span class="monospaced">lambda-free.sig</span></a>
54 <a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun"><span class="monospaced">lambda-free.fun</span></a>
61 <h2 id="_details_and_notes">Details and Notes</h2>
62 <div class="sectionbody">
63 <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
64 the frees of the entire group of mutually recursive functions. Hence,
65 <span class="monospaced">lambdaFree</span> for every <span class="monospaced">Lambda</span> in a single <span class="monospaced">Fun</span> dec is the same.
66 Furthermore, for a <span class="monospaced">Lambda</span> bound in a <span class="monospaced">Fun</span> dec, <span class="monospaced">lambdaRec</span> gives
67 the list of other functions bound in the same dec defining that
68 <span class="monospaced">Lambda</span>.</p></div>
69 <div class="paragraph"><p>For example:</p></div>
70 <div class="listingblock">
71 <div class="content monospaced">
72 <pre>val rec f = fn x => ... y ... g ... f ...
73 and g = fn z => ... f ... w ...</pre>
75 <div class="listingblock">
76 <div class="content monospaced">
77 <pre>lambdaFree(fn x =>) = [y, w]
78 lambdaFree(fn z =>) = [y, w]
79 lambdaRec(fn x =>) = [g, f]
80 lambdaRec(fn z =>) = [f]</pre>
85 <div id="footnotes"><hr></div>
87 <div id="footer-text">
89 <div id="footer-badges">