Termination
Learn about the termination of programs.
We'll cover the following...
We'll cover the following...
Once we start writing recursive functions, we need to worry about the termination of our programs (i.e. do they return a result in a finite amount of time?
Non-termination
It is possible to write recursive functions that do not terminate.
loop :: Int -> Int
loop x = loop x
Here, the right hand side of the only equation of loop is identical to its left hand side. So, the evaluation of an expression like loop 1 will make no progress:
loop 1
= loop 1
= loop 1
= ...
If we try to evaluate an expression like loop 1 in ghci, it will loop forever. You can cancel computations in ghci by hitting CTRL + C on ...