Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / LambdaFree
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
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">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>LambdaFree</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
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>
33 </div>
34 </div>
35 <div class="sect1">
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>
41 </div>
42 </div>
43 <div class="sect1">
44 <h2 id="_implementation">Implementation</h2>
45 <div class="sectionbody">
46 <div class="ulist"><ul>
47 <li>
48 <p>
49 <a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig"><span class="monospaced">lambda-free.sig</span></a>
50 </p>
51 </li>
52 <li>
53 <p>
54 <a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun"><span class="monospaced">lambda-free.fun</span></a>
55 </p>
56 </li>
57 </ul></div>
58 </div>
59 </div>
60 <div class="sect1">
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 =&gt; ... y ... g ... f ...
73 and g = fn z =&gt; ... f ... w ...</pre>
74 </div></div>
75 <div class="listingblock">
76 <div class="content monospaced">
77 <pre>lambdaFree(fn x =&gt;) = [y, w]
78 lambdaFree(fn z =&gt;) = [y, w]
79 lambdaRec(fn x =&gt;) = [g, f]
80 lambdaRec(fn z =&gt;) = [f]</pre>
81 </div></div>
82 </div>
83 </div>
84 </div>
85 <div id="footnotes"><hr></div>
86 <div id="footer">
87 <div id="footer-text">
88 </div>
89 <div id="footer-badges">
90 </div>
91 </div>
92 </body>
93 </html>