Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / LambdaFree.adoc
CommitLineData
7f918cf1
CE
1LambdaFree
2==========
3
4<:LambdaFree:> is an analysis pass for the <:SXML:>
5<:IntermediateLanguage:>, invoked from <:ClosureConvert:>.
6
7== Description ==
8
9This pass descends the entire <:SXML:> program and attaches a property
10to each `Lambda` `PrimExp.t` in the program. Then, you can use
11`lambdaFree` and `lambdaRec` to get free variables of that `Lambda`.
12
13== Implementation ==
14
15* <!ViewGitFile(mlton,master,mlton/closure-convert/lambda-free.sig)>
16* <!ViewGitFile(mlton,master,mlton/closure-convert/lambda-free.fun)>
17
18== Details and Notes ==
19
20For `Lambda`-s bound in a `Fun` dec, `lambdaFree` gives the union of
21the frees of the entire group of mutually recursive functions. Hence,
22`lambdaFree` for every `Lambda` in a single `Fun` dec is the same.
23Furthermore, for a `Lambda` bound in a `Fun` dec, `lambdaRec` gives
24the list of other functions bound in the same dec defining that
25`Lambda`.
26
27For example:
28----
29val rec f = fn x => ... y ... g ... f ...
30and g = fn z => ... f ... w ...
31----
32
33----
34lambdaFree(fn x =>) = [y, w]
35lambdaFree(fn z =>) = [y, w]
36lambdaRec(fn x =>) = [g, f]
37lambdaRec(fn z =>) = [f]
38----