<A target="_top" HREF="manual_contents.html"><img align=center src="contents.gif" ALT="Contents"></A> Up Previous Next

Stand-alone program execution

Once a program has been developed and debugged, the Hugs command loop can be eliminated and the program can be executed immediately without any command to run it. A slightly modified version of the interpreter called runhugs loads the program specified as its first argument and runs main in module Main. Unlike the interactive Hugs system, runhugs makes command arguments available to the running Hugs system. The first argument, specifying the program, is removed from the argument list. Arguments to Hugs itself preceed the program name. For example,
runhugs -h1000000 foo.hs arg1 arg2
runs the program foo.hs. The argument -h1000000 is used to set the heap size of Hugs and is not passed on to foo.hs, while both arg1 and arg2 are returned by the getArgs function in the System library. The program is executed by running main in module Main. Programs that do not define main cannot be executed by runhugs.

On Unix systems, executable programs may be created by placing runhugs in the first line of an executable file, like so:

#!/usr/local/bin/runhugs -h10k

module Main where
main = putStr "Hello, World\n"

The Hugs parser treats lines beginning with #! as comments, whether in literate or non-literate Haskell programs. Stand-alone programs can import other modules using import chasing. The runhugs program uses the same environment variables to set Hugs options as the standard Hugs systems. The stand-alone Hugs program may return an exit code.

On Windows 95/NT, runhugs may be invoked using a file extension that is set up to call runhugs rather than hugs. See hugs/docs/windows-notes.txt for details.