let <declarations> in <expression>
:let-in
and where
in combination β for example, let's write a function that checks whether the sum of squares of two numbers is a multiple of five:let-in
andwhere
. What we define in the where
declarations is accessible to any code above it, however, the declarations from the let
block are only accessible in the in
block of the let-in
clause. For example, we could try to calculate the remainder from the division by five in the where clause using the sum
from the let
clause, but it will not work:sum
is only accessible in the in
clause of the code. This means that with let-in
we can create super-localised expressions that aren't accessible anywhere outside the in
code block.