The Glasgow Haskell Compiler
Haskell is a non-strict purely-functional programming language, and
the Glasgow Haskell Compiler (GHC) is a terrific compiler for it. This
page is mainly about GHC, but also has pointers to more info about Haskell
and other Haskell implementations.
(Many of the links in this page are to compressed PostScript of
published papers that describe the relevant features of GHC in some
detail. Those that do have approximate page counts attached).
Haskell is a non-strict purely-functional programming language.
Designed by an international group, it has become a de facto standard.
Haskell 1.4 is the latest version (March, 1997), and the Report is
available from Yale.
Haskell 1.4 is accompanied by a separate
report describing Haskell's libraries. The libraries report is
currently (March '97) only in draft form. A tutorial
on Haskell is also available.
The previous Haskell
Report [160 pages] (version 1.2) was
published as a special issue of SIGPLAN Notices (Vol. 27, No. 5, May
1992) along with a tutorial [50 pages]
on the Haskell language, version 1.2. The tutorial is also available
as a "literate" Haskell program
which can be compiled by all the major Haskell compilers.
The
Glasgow
Haskell compiler (GHC) [10 pages] is a fully-featured implementation
of Haskell, together with a number of useful extensions.
GHC is directed at two main groups of users:
- Application writers.
We think that Haskell is a great language to write
applications in, and are dead keen for GHC to be used for this purpose.
To this end we have worked hard on GHC's external interfaces: the ability
to call and exchange data with C, a comprehensive I/O system, a developing
graphical user interface toolkit, and so on. (If you are interested, here's
a list of some
real-world applications of functional languages.)
- Implementors.
GHC is specifically designed to act as a "motherboard" into which others
can "plug in" their own strictness analyser, profiler, front end,
back end, or other special pass. Learning enough about GHC to do this is
a fairly substantial exercise, but it's a lot quicker than writing the whole
system yourself. Even more important, it means that there's enough scaffolding
to really stress your gizmo against real programs
(the NoFib suite provides some...), rather than toy ones.
Execution performance is in the top league for non-strict languages. (Hartel's
papers give some independent data points for this claim:
"Benchmark1" [1993, 9 pages],
"Benchmark2: [1995,6 pages],
and
"Pseudoknot" [1995,25 pages, draft].)
And arbitrary amounts of "versus C" speed can be clawed back, by
using GHC language extensions (the "Pseudoknot" paper above gives a good
example of this claw-back).
GHC provides an extensible,
monadic
input/output system [10 pages]
that fully supports the Haskell 1.4 I/O specification.
GHC also includes a Posix "system library",
which provides access to POSIX-compliant operating system
facilities. For example, you can write a
Unix shell in GHC.
Here's a tutorial on monadic I/O [19 pages] by Kevin Hammond and Andy Gordon.
GHC provides the ability to call arbitrary in-line C-language code, using the I/O
monad to retain referential transparency. (Indeed, the whole of
the I/O system is implemented in Haskell using this facility).
Pointers to external objects (malloc'd C structures, say) can be passed to Haskell;
these will be explicitly finalised when the Haskell garbage collector discovers
they are no longer referenced. For example, we have used this facility when
re-using an image-processing library written in C.
Pointers to Haskell structures can be passed to C, provided they are first registered
as "stable pointers", so that the garbage collector knows about them.
Quite a few people have developed X Window System interfaces for Haskell,
but they usually buy into the spaghetti event-loop model that is
used by most GUI programs. We are now developing,
Haggis [15 pages] a more substantial
GUI toolkit, based on Concurrent Haskell.
For more details, please consult the Haggis page.
GHC provides a few significant extensions to Haskell:
-
Fully fledged
unboxed
data types [12 pages].
Unboxed data types are extensively used inside
the compiler, but they also provide a route for the dedicated programmer
to squeeze quite a bit more performance out of critical programs.
They are also very useful when mapping flat C structures into the Haskell world.
-
Securely encapsulated mutable variables and incrementally-updatable arrays,
both embedded in a
state transformer monad [12 pages],
of which the I/O monad is a special case.
This provides the ability to write the occasional "imperative" algorithm,
and encapsulate it in such a way that its imperative nature is guaranteed not
to escape. The implementation of arrays in GHC is based on this technique,
but again it is occasionally useful for programmers.
GHC supports both parallel and concurrent programming.
Parallelism
By "parallel" we mean using implicit parallelism to gain performance.
Functional programmers have often made claims about parallel execution,
but very few (or even none?) non-toy parallel implementations are publicly available.
We have been guilty of this as well, but no longer!
GHC supports parallel execution based on a distributed-memory
store model. It currently sits on top of PVM, which means it can be made to run
on virtually anything; currently we support networks of workstations and Sun Solaris
shared-memory multiprocessors.
GranSim simulator
As well as running your programs on a parallel machine, you can also
simulate parallel execution on a uniprocessor. The simulator, called
GranSim [20 pages],
allows you to control a whole variety of parameters, including
message latency, and collects more detailed execution profiles than
the real parallel implementation does.
GranSim is fully operational, beginning with GHC 0.29. The
GranSim Home Page discusses GranSim in more detail and gives examples how to use it. The GranSim User's Guide is also available on-line (PostScript Version).
Some applications are most easily expressed in a programming language
that supports concurrency, notably interactive and distributed systems.
The goal is not so much performance but rather expressiveness, and the
concurrency is absolutely explicit, rather than implicit.
We have made some modest extensions to Haskell to allow it to express this
class of
explicitly-concurrent applications; we call the resulting language
Concurrent Haskell [20 pages],
by analogy with Reppy's Concurrent ML.
GHC has an effective
profiling system [12 pages],
that enables you to find out which
bits of your program are eating both time and space.
Patrick Sansoms's PhD thesis,
"Execution profiling for non-strict functional languages" [200 pages],
gives the details.
The GHC distribution comes with extensive documentation on both
configuring and using the compiler. The documentation is also
available on the Web:
-
GHC is written in Haskell, generates C as its target code -- hence there is some
chance of wide portability. For some architectures, the compiler also has the option
of generating native codes (x86, Sparc and Alpha).
-
GHC has a highly configurable runtime system. It makes heavy use of C macros, so
that you can modify much of the storage representation without
telling the compiler. For example, the system comes with 4
different garbage collectors, including a
generational one [12 pages],
and a combined two-space and one-space collector
[12 pages],
[28 pages].
-
Internally, the compiler makes extensive use of the second-order lambda calculus as an
intermediate code.
-
GHC uses
the
Spineless Tagless G-machine [50 pages]
is its evaluation model.
-
The compiler is based on the idea of
compilation by transformation [25 pages].
As much
as possible of the compilation process is expressed as correctness-preserving
program transformations.
Andre Santos' PhD thesis,
"Compilation by Transformation in Non-Strict Functional Languages" [200 pages],
gives a detailed discusison.
-
GHC has a simple but effective strictness analyser.
Here's
a
paper that describes the analyser and presents detailed measurements of
its effectiveness [20 pages].
-
GHC uses a
simple
but practical and effective
deforestation technique [12 pages]
to eliminate the intermediate lists that are often found in functional programs.
The general contact for GHC-related stuff is
Simon Peyton Jones,
Department of Computing Science,
Glasgow University,
Glasgow, SCOTLAND
G12 8QQ.
Email: glasgow-haskell-users-request@dcs.gla.ac.uk
Version 2.05 is the current release of GHC [July 97]; it is a
compiler for Haskell 1.4, and is of "decent beta quality".
We also supply GHC version 0.29 [July 96]; it is an up-to-date version
of our "old" compiler for Haskell 1.2; it is comparatively solid.
Please see
the online documentation for
full details.
The GHC installation guide
gives full porting info
about how well GHC is supported on different platforms.
GHC is available for download in a couple of ways, the most convenient
being way to grab it is via this WWW
download page.
If you prefer the more direct route, GHC is also available by anonymous FTP
(username: anonymous; password: your e-mail address) is possible from the following sites:
Site Host name
Chalmers ftp.cs.chalmers.se
Glasgow ftp.dcs.gla.ac.uk
Yale haskell.cs.yale.edu
Nottingham ftp.cs.nott.ac.uk
UKUUG sunsite.doc.ic.ac.uk
(computing/programming/languages/haskell mirrors Glasgow)
In each case, you'll find the directories:
pub/haskell/report The Haskell report
pub/haskell/tutorial The Hudak/Fasel tutorial
pub/haskell/glasgow GHC
Other subdirectories of pub/haskell contain other Haskell compilers.
Note: Specialised material related to a specific implementation (e.g.,
HBC binaries for the Obscuro 1000) may only be at the implementation's
"home site".
`Archie' and similar tools may help you find things which are cached
closer to you.
There is an electronic mailing list to discuss technical issues
related to Haskell. To join this list, send your request to
majordomo@dcs.gla.ac.uk
; the body of the message
should be:
subscribe haskell Your Name <your-email@where.you.are>
There are also implementation-specific mailing lists. In the case
of GHC they are:
glasgow-haskell-users@dcs.gla.ac.uk
glasgow-haskell-bugs@dcs.gla.ac.uk
The -bugs list is for reporting of and discussion about bugs in GHC.
The -users list is for GHC users to chat among themselves (about GHC-related matter).
In each case, to join, send a message to
majordomo@dcs.gla.ac.uk
; the body of the message
should be:
subscribe glasgow-haskell-<which> Your Name <your-email@where.you.are>
Both mailing lists have on-line archives:
glasgow-haskell-users
and
glasgow-haskell-bugs.
To contact the list administrator,
send a message to list-request
(eg glasgow-haskell-users-request
).
You can find a wad of Haskell-related research starting from the
Glasgow Functional Programming Group home page;
papers by members
of this group are in pub/glasgow-fp
, at ftp.dcs.gla.ac.uk
.
Lastly, here's a pointer to the competition:
other Haskell compilers.
Here are the main people working on GHC at present:
And here are some of the other people who have contributed to GHC
in the past:
Last modified: Tue 12 Aug 22:37 BST 1997 by sof@dcs.gla.ac.uk