Reduction of Nested let (assoc.ml)

Next, for the purpose of improving the appearance of expressions, we flatten nested let from let x = (let y = e1 in e2) in e3 to let y = e1 in let x = e2 in e3. This "reduction" does not (directly) affect the efficiency of programs compiled by MinCaml, but makes it easier for you to understand the intermediate code in debugging and experiments.

This transformation is implemented by Assoc.f. For expressions of the form let x = e1 in e2, we first reduce e1 to e1' and e2 to e2' by recursion. Then, if e1' is like let ... in e, we return the expression let ... in let x = e in e2'. The implementation is a little tricky but simple once it is finished. (assoc.ml is only 21 lines.)

Next