Using a variable list
It's possible to define variables in between the
let
and the
in
keywords. The value of these variables can then be used in the part after the
in
.
let
variable_1 = 18,
unused_variable = 99,
variable_2 = 24
in
variable_1 + variable_2
This code produces the same result as the «most simple let expression» above.
When a let expression is evaluated, the dependencies between variables in the variable list are resolved automatically. In the following example, bar
is assigned first, then baz
followed by foo
calculated, resulting in 42.
let
foo = 2 * baz,
bar = 7,
baz = 3 * bar
in
foo
Nested let expressions
let expressions can be nested. The following expression results in 6:
let
one = let
a = -2,
b = 3
in
a + b,
two = let
c = 5,
d = 3
in
c - d,
three = let
e = 1
in
e + two
in
one + two + three