Let Expressions

Posted by Beetle B. on Sat 30 July 2016


let b1 b2 ... bn in e end

The keywords are let, in, end.

bi are bindings.

e is an expression.

Note that often bi are each on their own line for readability.

Type Checking

Evaluate each binding in turn, and augment the static environment with it. Note that b3 will have access to b1 and b2.

This augmented environment is available to e, but not to the current environment.

The type of the whole expression is the type of e.

Note that any of the bindings could cause a previously defined variable to be shadowed.


The evaluation is the result of evaluating e.


It is a common idiom to have one of the bindings be a convenience function to prevent pollution of the environment.

Use let expressions to avoid repeated computations.