The behaviour of Hugs may be modified by options. These are initially set to default values, and then read from the following sources in order:
(Windows only) the registry under the HKEY_LOCAL_MACHINE
key.
(Windows only) the registry under the HKEY_CURRENT_USER
key.
This is where options set using the :set command are saved
(see Section 2.1).
This step is skipped if the environment variable
IGNORE_USER_REGISTRY
is set,
providing an emergency workaround if the settings are invalid.
(Hugs for Windows only) the GUI settings.
(Mac OS prior to Mac OS X)
the preferences file “Hugs Preferences
”.
The environment variable HUGSFLAGS
, if set.
The Hugs command line.
In each of the above cases except command line arguments,
the string should consist of zero or more options separated by whitespace.
To include a literal space in an option, either precede it with a backslash
or wrap the whole option in double quotes.
Double quoted options may also contain the escape sequences
“\
”,
“\"
” and
“\\
”.
Other backslashes are interpreted literally.
Most options can be changed within Hugs using the :set command (see Section 2.1).
Hugs takes two kinds of options:
Toggles like +t
or -t
,
which start with +
or -
to turn them on or off, respectively.
Options that set a parameter value, like
-P
str
,
in which -
could be replaced by +
,
the choice making no difference.
A special option is provided to allow several options in a single argument:
-X
str
The string str
is interpreted as an option string,
in the manner described above.
This is useful, for example, in some uses of runhugs
(see Section 4.1).
+98
Accept only Haskell 98. This is on by default, and cannot be changed within Hugs. Turning this off enables several special Hugs extensions, which are described in Chapter 6, Chapter 7 and the “Hugs 98 User Manual”.
-c
num
Set the constraint cutoff limit in the type checker to
num
(default: 40).
See Section 6.2.2.
+o
Allow certain overlapping instances (a Hugs extension; default: off). See Section 6.2.3 for details.
+O
Allow certain overlapping instances (a Hugs extension; default: off).
These are the same overlapping instances as accepted by +o
,
but +O
also accepts ambiguous uses of these instances,
even though this is unsafe (see Section 6.2.3).
+H
Support here documents (named after similar things in Unix shells), another way of writing large string literals (see Section 7.3). This extension is turned off by default.
+l
Literate scripts as default (default: off).
Files with names ending in “.hs
”
are always treated as ordinary Haskell,
while those ending in “.lhs
”
are always treated as literate scripts.
This option determines whether other files are literate scripts or not.
(See Section 4.1 for an example.)
+.
Print dots to show progress while loading modules (default: off).
+q
Print nothing to show progress while loading modules (default: on).
+w
Always show which files were loaded (default: off).
-F
cmd
Preprocess source files before loading.
Instead of reading a source file directly, Hugs will
execute cmd
with the source file name as argument,
and read the standard output.
This is handy for preprocessing source files with the C preprocessor, or some preprocessor implementing a language extension. However it is slower. In particular (because of the way Hugs handles imports), the preprocessor will be run twice on files that import modules that have not been loaded yet.
-P
str
Set search path for source files to str
,
which should be a list of directories separated by colons
(semicolons on Windows, DOS or Macs).
A null entry in this list will be replaced by the previous search path;
a null str
means the default path.
Any occurrences of {Hugs}
in this string will be replaced
by the Hugs library directory.
Similarly, {Home}
is expanded to your home directory.
An entry of the form
“directory
/*
”
means all the immediate subdirectories of directory
.
(See Section 3.4 for a way of using this.)
On Unix, the default value is
.:{Home}/lib/hugs/packages/*:{Hugs}/packages/*
The interpreter won't let you change the search path if that would
prevent it from reading the Prelude
.
If an entry occurs more than once in the search path, the extra copies
will be removed, as searching them would be a waste of time.
-S
str
Set list of filename suffixes.
Normally, when you import a module M
,
Hugs looks for files
and M
.hs
in each directory in you search path.
With this option, you can change this list,
in a similar way to the M
.lhs-P
option for the search path.
By default, the suffix list is “.hs:.lhs
”,
which gives the behaviour just described.
(NB: the “:
” is the Unix separator.
Windows or Macs use “;
” instead.)
If you use -S:.xhs
then the suffix
list becomes “.hs:.lhs:.xhs
”,
so Hugs will look for
,
M
.hs
and M
.lhs
.
M
.xhs
A null entry in this list will be replaced by the previous suffix list;
a null str
means the default list.
The interpreter won't let you change the suffix list if that would
prevent it from reading the Prelude
,
i.e. you must include “.hs
”.
Note also that the interpreter knows that files ending in
“.lhs
” are literate scripts;
no other suffix is treated that way.
This option can be useful in conjunction with the preprocessor option
(-F
).
The preprocessor can examine the filename to decide what to do with the file.
-E
str
Specify the editor used by the :edit
command
(see Section 2.2).
For example, to have Hugs invoke vi
to edit your files,
use
-Evi
The argument string is actually a template string that gets expanded by Hugs, via the following rules:
all occurrences of %d
are replaced by the line number
of where the last error occurred (if any).
Please consult your editor's documentation for ways of specifying the
line number.
all occurrences of %s
are replaced by the name of the file.
If an occurrence of %s
is both preceded by and followed
by space, the filename is enclosed in double-quotes.
all occurrences of %f
are replaced by the absolute filename
(provided your platform lets you find the absolute path to a file.)
Most of the time, %s
will be just fine, but in case your
editor doesn't handle relative filenames correctly, try
using %f
.
all occurrences of %%
are replaced by %
.
(Win32 only): if the -E
string is prefixed with
the character “&
”,
then the invocation is asynchronous, that is, the editor process
is created, but Hugs won't wait for the editor to terminate.
(Win32 only): if the -E
string is prefixed with
the character “!
”,
then the invocation will be asynchronous and use the underlying
command processor/shell to execute the command.
If neither %s
nor %f
occurs within
the -E
string,
then the filename is appended before invoking the editor.
Here are some example editor configurations:
-E"c:/Program Files/TextPad 4/textpad \"%s\"(%d)"
-E"vi +%d %s"
-E"gnuclient +%d %s"
-p
str
Set prompt string to str
(default: “%s>
”).
Any %s
in str
will be replaced by the current module name.
-r
str
Set the string denoting the last expression to str
(default: “$$
”).
+k
Show kind errors in full (default: off).
In Haskell, each type expression has a kind.
These kinds do not appear in the source language,
but they are checked for consistency.
By default, Hugs reports such errors as an Illegal type
.
For example, the declaration
instance Monad Int
gives rise to the error
ERROR "Test.hs":4 - Illegal type in class constraint
However if +k
is given,
the error message is identified as a Kind error,
and is expanded to include the conflicting kinds:
ERROR "Test.hs":4 - Kind error in class constraint *** constructor : Int *** kind : * *** does not match : * -> *
Also, when +k
is given,
the output of the :info will include kind information
for classes and type constructors:
Hugs> :info Monad -- constructor class with arity * -> * ... Hugs> :info Int -- type constructor with kind *
+T
Apply defaulting rules to types before printing (default: off).
When printing out types, the interpreter will normally not try to simplify types by applying defaulting rules, e.g.,
Hugs> :t 1 1 :: Num a => a Hugs>
With the +T
option,
the interpreter attempts to “default” types first,
using the same rules as for expressions (see Section 2.1):
Hugs> :set +T Hugs> :t 1 1 :: Integer Hugs>
+Q
Qualify names when printing (default: off).
By default, the interpreter will print out names without qualifying
them with their defining modules.
Most of the time that's exactly what you want,
but can become confusing if you re-define types and functions;
the error messages not pinning down what entity it is referring to.
To have the interpreter qualify the names, use +Q
.
Typically, you use +Q
when resolving errors,
but turn it back off again afterwards.
+t
Print the type of each expression evaluated (default: off).
Normally Hugs merely prints the value of each expression evaluated:
Hugs> 1+2 3
With the +t
option, it also adds the type of the expression:
Hugs> :set +t Hugs> 1+2 3 :: Integer
Note that defaulting has been applied to the type of the expression in order
to evaluate it, so the type differs from that reported by the
:type command (assuming that the
+T
option
is not used):
Hugs> :type 1+2 1 + 2 :: Num a => a
+u
Use show
to display results (default: on).
By default, the values of expressions typed at the prompt are printed using
the show
member of the Show
class:
Hugs> [Just (2+3), Nothing] [Just 5,Nothing]
You can define this function as desired for any new datatype.
If the type of the expression is not an instance of the
Show
class, an error results:
Hugs> id ERROR - Cannot find "show" function for: *** Expression : id *** Of type : a -> a
With the -u
option, a built-in printer is used instead,
and this works for any type:
Hugs> :set -u Hugs> id id Hugs> \x -> x v1497 Hugs> [Just (2+3), Nothing] [Just 5,Nothing]
Another feature of the built-in printer is its treatment of failures (or exceptions). Normally, an exception causes immediate failure of the expression:
Hugs> :set +u Hugs> 1 + 2/0 Program error: divide by zero Hugs> [1, 2 + error "foo", 3] [1, Program error: foo
However the built-in printer prints the whole value, with embedded exceptions:
Hugs> :set -u Hugs> [1, 2 + error "foo", 3] [1,{error "foo"},3]
Sometimes a component could produce one of two or more exceptions, but the built-in printer shows only one of them:
Hugs> 1 + error "foo" + error "bar" {error "foo"}
+I
Display results of IO programs (default: off).
By default, an expression of IO
type typed at the prompt
is executed for effect, but the final value it produces is discarded.
When +I
is used, such an expression is evaluated,
and then its result is printed with Prelude.print
:
Hugs> :set +I Hugs> (return 'a' :: IO Char) 'a' Hugs>
i.e., evaluating an IO action m
with +I
in effect is equivalent to evaluating
“do { x <- m ; print x }
”
with -I
.
-h
num
Set the maximum size in the Hugs heap (default: 250k
).
The argument should be a decimal number, and may by suffixed with
“k
” (thousands),
“M
” (millions) or
“G
”
(billions, if your machine has that much memory).
Case is not significant.
The heap size is measured in cells,
each of which usually comprises two int
s
(taking up 8 bytes on most common architectures).
Setting this option with :set does not change the heap size for the current execution of Hugs. On Win32, however, all options are saved to the registry, so it will take effect the next time Hugs is run.
+s
Print statistics after each evaluation (default: off).
For each evaluation, this option shows
the number of reductions performed (a crude measure of the amount of work performed by the interpreter),
the total number of cells allocated during evaluation, and
the number of garbage collections that occurred during evaluation (if any).
Note that even the most trivial evaluation involves several reductions and cells, because Hugs wraps the expression in code to print the value and catch exceptions:
Hugs> True True (25 reductions, 46 cells)
Note that the cell count measures the total amount of allocation,
rather than the number of cells in use at any time
(the residency).
For that, the +g
option may be more useful.
In general these statistics cannot be safely used for much more than
spotting general trends.
+g
Print the number of cells recovered after each garbage collection (default: off). This can be useful for analysing the residency of an algorithm, the amount of memory it is actually using at each point in time. For example,
Hugs> :set +g Hugs> length [1..60000] {{Gc:237618}}{{Gc:237617}}{{Gc:237616}}{{Gc:237623}}{{Gc:237621}} {{Gc:237628}}{{Gc:237623}}{{Gc:237618}}60000
We see that the computation creates a lot of cells, but the number recovered on each garbage collection is roughly the same, so its residency is constant. In contrast, with
Hugs> let xs = [1..60000] in sum xs `div` length xs {{Gc:237510}}{{Gc:213862}}{{Gc:190948}}{{Gc:170500}}{{Gc:152225}} {{Gc:135925}}{{Gc:121350}}{{Gc:108350}}{{Gc:96750}}{{Gc:86375}} {{Gc:77125}}{{Gc:68860}}{{Gc:61490}}{{Gc:72948}}{{Gc:97265}} {{Gc:129688}}{{Gc:172916}}{{Gc:230551}}30000
we see that the amount reclaimed by each garbage collection is steadily
falling until a certain point (because the original list is retained).
These examples use the default heap size of 250000 cells;
this may be changed with the
-h
option.
Since these garbage collection messages will be unpredictably interleaved
with the desired output, you would usually only turn +g
on to analyse memory problems, and then turn it off afterwards.
+R
Enable root optimisation (default: on).
This usually gives a small gain in speed, but you might want to turn it off if you're using the observation-based debugger (see Section 7.4.2.3).