let
let Statement
The let
Statement gives names to data.
let x: Int = 1 + 2;
Type annotation is freely optional.
let x = 1 + 2;
This Statement computes the expression 1 + 2
(the result is 3
of course),
and we call it x
.
Frankly, this is a variable,
and you can use x
as a Value.
The last ;
is required.
This Statement can be denoted by following BNF;
<let> ::= `let` <name> `=` <expression> `;`
| `let` <name> `:` <type> `=` <expression> `;`
<name> ::= <identifier>
shadowing
When some variables are defined already,
you can declare the same names with let
.
New data shadows old data.
let x = 1;
// Here, x is Nat 1.
let x = "hoge";
// Here, x is String "hoge".
Once variables are shadowed, they cannot be used.