next up previous
Next: Conditional statements (If-then-else) Up: The Frightened Freshers Guide Previous: Importing other modules

Step-by-step evaluation

If we define a function called myMax which returns the max number from a pair of inputs:


\begin{lstlisting}
myMax x y = if x >= y then x else y
\end{lstlisting}

It is possible to evaulate this step-by-step:


\begin{lstlisting}
- myMax 7 3
- if 7 >= 3 then 7 else 3
- if True then 7 else 3
- 7
\end{lstlisting}

Although this is a very simple example, all functions no matter how complex can be broken down in this way into their component parts and evaulated in a simple way. With a very large function this may take quite some time, and one of the major disadvantages of the hugs haskell interpreter is that you can not tell it to step through the evaluation. Debugging may involve a manual walkthrough of the code!



Tom Carlson 2006-04-11