The Hugs 98 User's Guide
Prev |  | Next

# Chapter 3. Changing the behaviour of Hugs

# 3.1. Hugs options

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:

1. (Windows only) the registry under the `HKEY_LOCAL_MACHINE` key.

2. (Windows only) the registry under the `HKEY_CURRENT_USER` key. This step is skipped if the environment variable `IGNORE_USER_REGISTRY` is set, providing an emergency workaround if the settings are invalid.

3. (Hugs for Windows only) the GUI settings.

4. (Mac OS prior to Mac OS X) the preferences file "`Hugs Preferences`".

5. The environment variable `HUGSFLAGS`, if set.

6. The Hugs command line.

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.

## 3.1.1. Language options

`+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 5, Chapter 6 and the Hugs 98 User Manual.

`-c` `num`

  Set constraint cutoff limit in the type checker to `num` (default: 40). See Section 5.2.2.

`+o`

  Allow certain overlapping instances (a Hugs extension; default: off). See Section 5.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 5.2.3).

`+H`

  Support here documents (named after similar things in Unix shells), another way of writing large string literals (see Section 6.3). This extension is turned off by default.

## 3.1.2. Module loading options

`+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 3.3 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`. The default value is

      .:{Hugs}/libraries:{Hugs}/oldlib

  The interpreter won't let you change the search path if that would prevent it from reading the `Prelude`.

`-S` `str`

  Set list of filename suffixes.

  Normally, when you import a module `M`, Hugs looks for files `M``.hs` and `M``.lhs` in each directory in you search path. With this option, you can change this list, in a similar way to the `-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`, `M``.lhs` and `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.

## 3.1.3. Specifying a source file editor

`-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:

  - TextPad

          -E"c:/Program Files/TextPad 4/textpad \"%s\"(%d)"

  - vi and clones

          -E"vi +%d %s"

  - gnuclient (for use with (X)Emacs)

          -E"gnuclient +%d %s"

## 3.1.4. Evaluation and printing options

`-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:

        Prelude> :info Monad
        -- constructor class with arity * -> *
        ...
        Prelude> :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.,

        Prelude> :t 1
        1 :: Num a => a
        Prelude>

  With the `+T` option, the interpreter attempts to "default" types first, using the same rules as for expressions (see Section 2.1):

        Prelude> :set +T
        Prelude> :t 1
        1 :: Integer
        Prelude>

`+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:

        Prelude> 1+2
        3

  With the `+t` option, it also adds the type of the expression:

        Prelude> :set +t
        Prelude> 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):

        Prelude> :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:

        Prelude> [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:

        Prelude> 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:

        Prelude> :set -u
        Prelude> id
        id
        Prelude> \x -> x
        v1497
        Prelude> [Just (2+3), Nothing]
        [Maybe_Just 5,Maybe_Nothing]

  Another feature of the built-in printer is its treatment of failures (or exceptions). Normally, an exception causes immediate failure of the expression:

        Prelude> :set +u
        Prelude> 1 + 2/0

        Program error: divide by zero

        Prelude> [1, 2 + error "foo", 3]
        [1,
        Program error: foo

  However the built-in printer prints the whole value, with embedded exceptions:

        Prelude> :set -u
        Prelude> [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:

        Prelude> 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`:

        Prelude> :set +I
        Prelude> (return 'a' :: IO Char)
        'a'
        Prelude>

  i.e., evaluating an IO action `m` with `+I` in effect is equivalent to evaluating "`do { x <- m ; print x }`" with `-I`.

## 3.1.5. Resource usage options

`-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:

        Prelude> 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 is is actually using at each point in time. For example,

        Prelude> :set +g
        Prelude> 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

        Prelude> 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 6.4.2.3).

Prev | Home | Next
Miscellaneous commands |  | Environment variables used by Hugs