Running Hugs


The functional programming language Haskell has an implementation running on the CS cluster of Linux-workstations (B5 MLH, and 301 MLH). Programs are composed in a text file using the editor of your choice. The command to invoke the Haskell system is 'hugs' (see the on-line manual page for details). Note that files containing Haskell definitions are called scripts and must have a name that ends with '.hs' (or '.lhs', for literate scripts).


After starting the Haskell system with the 'hugs' command, the session is a series of interactions. At each Haskell prompt you enter a desired Haskell expression (or command) whose constituent functions are defined in a script (or are pre-defined), the value of the exprression will be displayed, and the prompt for the next input issued. The system automatically loads the definitions of basic facilities called the 'Prelude'. A session is terminated with the command ':quit' (or the end-of-file, control-D).


An entry with first character ':' is regarded as a command rather than an expression to be evaluated. The following commands (plus others) are available:

:quit - end Haskell session

:? - display info on the Hugs commands

:edit - edit current script (using default editor)

:load <file name>- loads the definitions contained in the specified file

:reload reload the last script file

Using the edit command allows you to switch between editing and executing your program without stopping and restarting Haskell (but remember to quit/save in the editor). There are various other commands permitted at the Haskell prompt and they are explained by the help command.


Haskell has extensive documentation available on-line (see the Haskell Web page). The "gentle introduction" linked there is a good starting place. The precise BNF syntax and related constraints are given in the Haskell Report along with detailed information on the pre-defined facilities.


The directory /usr/local/lib/hugs/oldlib contains a collection of example Haskell scripts, but they tend to be rather advanced. Other examples that we discuss in class will be placed in our class directory.


Anyone needing help using Linux should let me know. Also, note that general system assistance is available during selected hours in 301 MLH -- the hours are on the door and on the main CS Web page.


Selected Pre-defined (i.e., Prelude) Definitions


Arithmetic operators

+,-,*,/ as usual, with multiply ops greater precedence than adding ops, all left associative

x^y = x to power y for y non-negative Integral, with exponent ops greater precedence than multiply ops, right associative

x^^y = x to power y for y positive or negative Integral

Comparison operations

< <= == > >= (lower precedence than arithmetic ops)

Arithmetic functions

mod m n = remainder of integer m divided by integer n

quot m n = quotient of integer m divided by integer n

signum x = +1 or -1 depending on the sign of x

max, min, abs, sqrt, exp, log, sin, cos, -- as usual.


Boolean operators

|| (or, lowest prec), && (and, medium prec), associative

not (highest prec), prefix


List operators

!! , subscript (from 0, highest prec),
++, concatenation (lower prec)

List functions

init, tail, reverse -- basic list functions

head, last, length, elem -- extracting/testing on lists

take, takeWhile, drop, dropWhile, filter, zip -- iterative list processing

replicate -- construct list with repeated item


General constructors

map -- applies a function to every item of a list

foldl, foldr -- uses a binary function to coalesce all the items of a list into one value

until, iterate -- iterative (i.e., loops) use of functions