Local bindings are names used for expressions, which are used to improve the readability of code. These are also called definitions.

The where keyword

One way of defining definitions is using some alias in an expression and then defining them in an indented line below by where keyword.

These definitions are defined on the function-level meaning they are associated in the entire function.

Several definitions can be defined by nesting definitions after the where keyword.

Examples

fName = var1 + var2
        where
          var1 = 4
          var2 = 2
 
fName

The let keyword

The let keyword lets you make definitions by writing an alias and setting it equal to whatever it defines and then writing in to define the expression in which the definition is associated.

These definitions are defined only at the expression-level meaning that they will only be associated in the expression in which they are defined.

Multiple definitions can be made by writing them on the next line after a single use of the let keyword before writing in and the expression in which they will be associated.

Examples

Making multiple definitions

:{
addLet = let y = 10
             x = 32
               in x + y
:}
addLet

42

Unpacking data structures

x = (42,69)
:{
doubleFirst t = let (t1, t2) = t
              in t1*2
:}
doubleFirst x

84