Download Hugs 98 - Haskell

Transcript
sions 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]
[{primDivInt 1 0}]
Prelude> [1 ‘div‘ 0, 2]
[{primDivInt 1 0}, 2]
Prelude>
-- value is [bottom]
-- value is [bottom, 2]
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.
Garbage collector notification
+g,-g
It is sometimes useful to monitor uses of the garbage collector, and to determine
how many cells are recovered with each collection. If the +g option is set, then
the interpreter will print a message of the form {{Gc:num}} each time that the
garbage collector is invoked. The number after the colon indicates the total
number of cells that are recovered.
16