✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
You might have been surprised that Haskell is using = as a syntax for defining functions. Isn't = commonly used for assignments?
There are no assignments in Haskell: the proper name for the operation accomplished with = is binding. To bind means something like "tightly associate two things together".
What are we associating? Well, a name with an expression. For example:
ghci> favNumber = 42
ghci> twiceFavNumber = favNumber * 2
ghci> twiceFavNumber
84
Each = establishes an equation in the mathematical sense: twiceFavNumber is always replaceable with the expression favNumber * 2, and vice-versa favNumber * 2 is always replaceable with twiceFavNumber.
Defining functions is no different! We're binding the name of the function to its body. Whenever we see that name in the middle of the program, we can substitute it with the body of the function (replacing the parameters with the actual arguments). This way of reasoning about programs is known as equational reasoning.
To stretch this concept, define a parameterless function named loop that simply calls itself. Then, try to call it and see what happens.
Write the full definition of the loop function:
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!