Chapter 2. Using Hugs

The interpreter may be started with a command line of the form

hugs [option...] [file...]

On many systems it can also be found in the system menus, and may be started by (double) clicking on a file with a “.hs” or “.lhs” extension.

Hugs takes options from the command line and elsewhere (see Section 3.1), and then loads the Haskell Prelude module, as well as as any modules specified on the command line.

Hugs starts with a banner like

__   __ __  __  ____   ___      _________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
||   || Version:    March 2005  _________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Type :? for help
Hugs>

The prompt string Hugs> indicates that the current module is an empty module called Hugs (assuming no modules were specified on the command line). At this prompt, you can type Haskell expressions to be evaluated, and also enter commands of the form “:cmd”, where cmd may be abbreviated to a single letter.

2.1. Basic operation

expr

Evaluate a Haskell expression. The expression cannot be broken over multiple lines. Usually, the value is simply converted to a string (using show) and printed:

Hugs> 1+2
3

The printing style can be changed with the -u option (see Section 3.1.4).

However, if expr has type IO t for some type t, the resulting IO action is performed:

Hugs> print (1+2) >> putStrLn "bye"
3
bye

Usually the value produced by this action is ignored, but this can be changed with the +I option (see Section 3.1.4).

On ambiguous types

If the type of expr is ambiguous, defaulting is applied to each ambiguous type variable v whose constraints all have the form C v where C is a standard class, and at least one of these classes is a numeric class, or is Show, Eq or Ord. (This is an extension of the Haskell 98 rule applied to top-level definitions in modules, which requires a numeric class.) It is an error if any ambiguous type variables cannot be handled in this way. For example, consider

Hugs> reverse []
[]

Here a Show constraint on the list elements arises from Hugs's use of show to display the result, so the type of the elements defaults to Integer, removing the ambiguity.

:type expr

Print the type of expr, without evaluating it. Usually the defaulting rules (discussed above) are not applied to the type before printing, but this can be changed with the +T option (see Section 3.1.4).

:set [option...]

Set command line options. See Section 3.1 for a list of available options. On Win32, the new option settings are saved to the registry under the HKEY_CURRENT_USER key, and so persist across Hugs sessions. To make settings persistent on other systems, put them in the HUGSFLAGS environment variable.

If no options are given, list the available options and their current settings.

:main [argument...]

Run the main function, with the getArgs function returning the values specified for the arguments. This is useful for testing programs from the interpreter.

If your Main module imports System.Environment, you can get the same effect using withArgs, e.g.

withArgs ["Hello", "World"] main

:quit

Exit the interpreter.