17 Let Expressions

Let expressions are like let definitions, but they're expressions!

The in keyword makes this a let expression. All it does is replace all instances of a in the expression following in with the value assigned to a.

Here, b was bound to 2, so OCaml evaluated 1 * 2, which is 2.

See how b doesn't exist outside that expression? That's because it only is bound in that one expression.

This is pretty simple! First, d is bound to 4, and the expression c + 4 is returned from the inside let expression, then c is bound to 3, and 3 + 4 is returned, so, 7!

What if we use the same binding twice?

Wait! What's happening?