15 Let Definitions

Definitions let us give a name to a value. This is similar to the concept of a variable in other programming languages, but it can't change.

The val x : int = 42 means we have a value, named x, set to the int with value 42. The second expression simply evaluates to the int 42.

We can also specify a type:

We can also use these values!

Hey! CS 3152 is "Introduction to Computer Game Design!"


Expressions and definitions are completely different.

let definitions have the syntax

let x = e

where x is an identifier, and e is an expression.

It is evaluated:

  1. Evaluate e to value v.
  2. Bind v to x: henceforth, x will evaluate to v.

let definitions do not have a value themselves. They are not expressions.

For example, this will fail: