Hugs 98 and Hugs 1.4 Tutorial

       This tutorial shows you how to get started using Hugs98 and Hugs 1.4 (older version).  This is not a language tutorial.  For a language tutorial, please go to

            http://www.cs.washington.edu/education/courses/341/CurrentQtr/haskell/haskell.html

 

 

Environment Setup

Using Hugs (Example)

 

How to Get Started

Hugs98 (NT)

All Win NT platforms in 232 and 329 should have Hugs98.exe installed in the Local Hard Drive D.  You can access it at from the start menu

           Start : Programs : Desktop Tools:

at the bottom you should see Hugs98.

Running from D:\Hugs98\hugs.exe doesn't work because it cannot load the main module Prelude.hs from D:\Hugs98\lib.   It needs to change the HUGSFLAGS environment variable, so we will just run the program from the start menu.

 

Hugs1.4 (Orcas, SanJuan)

To run Hugs1.4 in Orcas or SanJuan, you need to go to the following directory:

             /cse/courses/misc_lang/axp/hugs-1.4/bin

then run hugs from there.

To avoid typing the directory everytime you use hugs1.4, just add the following line to your .cshrc file in your home directory:

             set path = ($path /cse/courses/misc_lang/axp/hugs-1.4/bin)

and hugs can be run from your directory.

 

(It is recommended to use Hugs98 rather than Hugs-1.4, if possible)

For more information about starting Hugs, visit

           http://haskell.cs.yale.edu/hugs/hugsman/started.htm

Environment Setup

When you run Hugs, you will see a Dos console that shows the following:

_     _    _    _  ___  ___            _________________________________________
||      ||    ||    ||  ||     || ||__             Hugs 98: Based on the Haskell 98 standard
||___||    ||__||  ||__ ||  __||            Copyright (c) 1994-1999
||----||             ___ ||                   World Wide Web: http://haskell.org/hugs
||      ||                                        Report bugs to: hugs-bugs@haskell.org
||      || Version: May 1999         _________________________________________

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

Reading file "Prelude.hs":

Hugs session for:
Prelude.hs
Type :? for help
Prelude>

Hugs starts off the program by loading the Prelude.hs.  This file contains standard definitions that are loaded into Hugs each time the interpreter is loaded.  (User input is red, output is green)

At Prelude>, type in

                 :?

to get a list of commands.  For more detailed explanation of the commands, go to

                http://haskell.cs.yale.edu/hugs/hugsman/commands.html

Now try typing in

                 :set

This command will let you view or change settings.  The following will show up

TOGGLES: groups begin with +/- to turn options on/off resp.
 s    Print no. reductions/cells after eval
 t    Print type after evaluation
 f    Terminate evaluation on first error
 g    Print no. cells recovered after gc
 l    Literate modules as default
 e    Warn about errors in literate modules
 .    Print dots to show progress
 q    Print nothing to show progress
 w    Always show which modules are loaded
 k    Show kind errors in full
 o    Allow overlapping instances
 u    Use "show" to display results
 i    Chase imports while loading modules

 OTHER OPTIONS: (leading + or - makes no difference)
 hnum Set heap size (cannot be changed within Hugs)
 pstr Set prompt string to str
 rstr Set repeat last expression string to str
 Pstr Set search path for modules to str
 Estr Use editor setting given by str
 cnum Set constraint cutoff limit
 Fstr Set preprocessor filter to str

 Current settings: +fwui -stgle.qko -h100000 -p"%s> " -r$$ -c16
 Search path     : -P{Hugs}\lib;{Hugs}\lib\hugs;{Hugs}\lib\exts;{Hugs}\lib\win32
 Editor setting  : -E
 Preprocessor    : -F
 Compatibility   : Hugs Extensions
 Prelude>

Notice where it saids "Editor setting", "-E" means that no text editor is set for editing.  Type in

                :set -ENotepad

to set your text editor to Notepad so that we can write functions in modules.

You may need to change the search path so that you can save the modules in your own directory and be able to load them.  To do so, type in

                :set -P{Hugs}\lib;{Hugs}\lib\hugs;{Hugs}\lib\exts;{Hugs}\lib\win32;Z:\chunyu\classes

(The last one is the directory where you put your own modules in)

If you just type

                :set -PZ:\chunyu\classes

Then the search paths to the standard libraries will be lost, thus you cannot use the functions in the standard library.  For more information about setting text editor and search path, go to

               http://haskell.cs.yale.edu/hugs/hugsman/started.html

 

Using Hugs (Examples)

In essence, using Hugs is just like a calculator.  The interpreter simply evaluates each expression that is entered, printing the results as it goes.

                Prelude>   (4+6) * 10

                100

Hugs can also represents sequences of numbers easily

                Prelude> sum[1..10]

                55

The standard library has a lot of 'cool' functions that can be use.

                Prelude> reverse "341 is fun"

                "nuf si 143"

Now we will try defining our own functions.  In order to use our functions many times, we must put our definitions and functions in a module that can be loaded and used by Hugs.  However, we may need to change our directory so that the module (file) is saved in our own directory.

                Prelude> :cd Z:\chunyu\classes

(Again put your own directory)

We will create a module called fact.hs

                Prelude> :edit fact.hs

Then Notepad (or your pre-set text editor) will come up and you can type the following in:

                module Fact where

                fact n = product [1..n]

(The module name should be the same as the file name).  After we have saved fact.hs, we can go back to Hugs98 and load fact.hs

                Prelude> :load fact.hs

(If you didn't change the search path, you can do Prelude> :load Z:\chunyu\classes\fact.hs to access your fact.hs)

Now you will see Fact>, this means that we are now in the Fact module.  We can now use the fact function that we have defined.

                Fact> fact 6

                720

 

Again if you want more information about the language. Please go to

                http://www.cs.washington.edu/education/courses/341/CurrentQtr/haskell/haskell.html

 

                                                                                     back to cse341