Prelude> [1 `div` 0]
[
Program error: {primDivInt 1 0}
Prelude> [1 `div` 0, 2]
[
Program error: {primDivInt 1 0}
Prelude>
This is often useful during program development because it means that
errors are detected as soon as they occur.
However, technically speaking, the two expressions above have different
meanings; the first is a singleton list, while the second has two elements.
Unfortunately, the output produced by Hugs does not allow us to distinguish
between the values.The -f option can be used to make the Hugs printing option a little more accurate; this should normally be combined with -u because the built-in printer is better than the user-defined show functions at recovering from evaluation errors. With these settings, if the interpreter encounters an irreducible subexpression, then it prints the expression between a matching pair of braces and attempts to continue with the evaluation of other parts of the original expression. For the examples above, we get:
Prelude> :set -u -f
Prelude> [1 `div` 0] -- value is [bottom]
[{primDivInt 1 0}]
Prelude> [1 `div` 0, 2]
[{primDivInt 1 0}, 2] -- value is [bottom, 2]
Prelude>
Reading an expression in braces as
bottom, the output produced here
shows the correct values, according to the semantics of
Haskell. Of course, it is not possible to
detect all occurrences of bottom like this, such as those produced by
a nonterminating computation:
Prelude> last [1..]
^C{Interrupted!} -- nothing printed until interrupted
Prelude>
Note that the basic method of evaluation is the same with both
the +f and -f options; all that changes is the way that
the printing mechanism deals with certain kinds of runtime error.