Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / LambdaFree
CommitLineData
7f918cf1
CE
1<!DOCTYPE html>\r
2<html lang="en">\r
3<head>\r
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\r
5<meta name="generator" content="AsciiDoc 8.6.9">\r
6<title>LambdaFree</title>\r
7<link rel="stylesheet" href="./asciidoc.css" type="text/css">\r
8<link rel="stylesheet" href="./pygments.css" type="text/css">\r
9\r
10\r
11<script type="text/javascript" src="./asciidoc.js"></script>\r
12<script type="text/javascript">\r
13/*<![CDATA[*/\r
14asciidoc.install();\r
15/*]]>*/\r
16</script>\r
17<link rel="stylesheet" href="./mlton.css" type="text/css">\r
18</head>\r
19<body class="article">\r
20<div id="banner">\r
21<div id="banner-home">\r
22<a href="./Home">MLton 20180207</a>\r
23</div>\r
24</div>\r
25<div id="header">\r
26<h1>LambdaFree</h1>\r
27</div>\r
28<div id="content">\r
29<div id="preamble">\r
30<div class="sectionbody">\r
31<div class="paragraph"><p><a href="LambdaFree">LambdaFree</a> is an analysis pass for the <a href="SXML">SXML</a>\r
32<a href="IntermediateLanguage">IntermediateLanguage</a>, invoked from <a href="ClosureConvert">ClosureConvert</a>.</p></div>\r
33</div>\r
34</div>\r
35<div class="sect1">\r
36<h2 id="_description">Description</h2>\r
37<div class="sectionbody">\r
38<div class="paragraph"><p>This pass descends the entire <a href="SXML">SXML</a> program and attaches a property\r
39to each <span class="monospaced">Lambda</span> <span class="monospaced">PrimExp.t</span> in the program. Then, you can use\r
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>\r
41</div>\r
42</div>\r
43<div class="sect1">\r
44<h2 id="_implementation">Implementation</h2>\r
45<div class="sectionbody">\r
46<div class="ulist"><ul>\r
47<li>\r
48<p>\r
49<a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig"><span class="monospaced">lambda-free.sig</span></a>\r
50</p>\r
51</li>\r
52<li>\r
53<p>\r
54<a href="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun"><span class="monospaced">lambda-free.fun</span></a>\r
55</p>\r
56</li>\r
57</ul></div>\r
58</div>\r
59</div>\r
60<div class="sect1">\r
61<h2 id="_details_and_notes">Details and Notes</h2>\r
62<div class="sectionbody">\r
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\r
64the frees of the entire group of mutually recursive functions. Hence,\r
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.\r
66Furthermore, for a <span class="monospaced">Lambda</span> bound in a <span class="monospaced">Fun</span> dec, <span class="monospaced">lambdaRec</span> gives\r
67the list of other functions bound in the same dec defining that\r
68<span class="monospaced">Lambda</span>.</p></div>\r
69<div class="paragraph"><p>For example:</p></div>\r
70<div class="listingblock">\r
71<div class="content monospaced">\r
72<pre>val rec f = fn x =&gt; ... y ... g ... f ...\r
73and g = fn z =&gt; ... f ... w ...</pre>\r
74</div></div>\r
75<div class="listingblock">\r
76<div class="content monospaced">\r
77<pre>lambdaFree(fn x =&gt;) = [y, w]\r
78lambdaFree(fn z =&gt;) = [y, w]\r
79lambdaRec(fn x =&gt;) = [g, f]\r
80lambdaRec(fn z =&gt;) = [f]</pre>\r
81</div></div>\r
82</div>\r
83</div>\r
84</div>\r
85<div id="footnotes"><hr></div>\r
86<div id="footer">\r
87<div id="footer-text">\r
88</div>\r
89<div id="footer-badges">\r
90</div>\r
91</div>\r
92</body>\r
93</html>\r