Keep Your Programs Tidy

Scoping is an important way to keep your programs tidy.
It involves limiting the region of the program in which
names ‘exist’ and can be used.

In Haskell, a let expression provides local scope.
A let expression has a series of equations defining
variable values and a final expression
(after the in keyword) that computes a value
with those variables in scope.

Here is an example:

letx=2inx*x

What will this expression evaluate to?

Multiple variables can be defined in a single let

letx=2y=3inx+y

What will this expression evaluate to?

Note that the variable names line up
underneath one another
This is good formatting practice, but is also needed
for Haskell to interpret the code correctly.
Like Python, whitespace is important in Haskell,
certainly in let expressions anyway!

Sometimes in a let, one of the variables might
depend on another — in the function below, gallons depends on
milespergallon: