Let Expressions

Posted by Beetle B. on Sat 30 July 2016

Syntax

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.

Evaluation

The evaluation is the result of evaluating e.

Miscellaneous

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.