Elimination of Unnecessary Definitions (elim.ml)

After constant folding, we often find unused variable definitions (and function definitions) like x and y in let x = 3 in let y = 7 in 10. MinCaml removes them by Elim.f.

In general, if e1 has no side effect and x does not appear in e2, we can replace let x = e1 in e2 just with e2. The presence of "side effects" is checked by Elim.effect and the appearance of variables are examined by KNormal.fv. However, since it is undecidable whether an expression has a real side effect, we regard any write to arrays and any call to functions as possible side effects.

By the way, the function KNormal.fv is named after the term free variables. For example, the expression let x = 3 in x + y has two variables x and y, where x is called a bound variable since it is defined as (or bound to) integer 3, while y is called free since it is not bound.