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.
let x = 42;;
val x : int = 42
x;;
- : int = 42
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:
let y : int = 3110;;
val y : int = 3110
We can also use these values!
x + y;;
- : int = 3152
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:
e to value v.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:
(let x = 42) + 1;;
File "[5]", line 1, characters 11-12:
1 | (let x = 42) + 1;;
^
Error: Syntax error: operator expected.