Glasgow Haskell Compiler

from Wikipedia, the free encyclopedia
Glasgow Haskell Compiler
Basic data

developer Simon Peyton Jones , Simon Marlow
Publishing year December 1992
Current  version 8.8.1
( August 25, 2019 )
operating system Platform independent (UNIX, Windows)
programming language Haskell
category Compiler
License BSD ( Free Software )
http://haskell.org/ghc/

The Glasgow Haskell Compiler , also known as The Glorious Glasgow Haskell Compilation System , but best known as GHC , is an open source compiler for the Haskell programming language . It was written in Haskell itself and now generates native machine code for the respective platform.

GHC is now considered the Haskell implementation with the most features and the most widespread use. In 2011 he received the Programming Languages ​​Software Award from ACM SIGPLAN.

history

Haskell was drafted after the 1987 Conference on Functional Programming Languages ​​and Computer Architecture , at which it became clear that the development of functional programming had been held back by its breakdown into many different languages ​​(many of which were members of the ML family). For this reason, a new comprehensive language should be designed, Haskell. The name was chosen as a tribute to the mathematician Haskell B. Curry .

Shortly thereafter, Kevin Hammond at the University of Glasgow (hence the name of the compiler) began developing an implementation in Lazy ML that practically represented a front end for an existing Lazy ML implementation. When this implementation was up and running (June 1989), Simon Peyton Jones joined the development group. At this point in time, the prototype already had all the properties described in Haskell 1.0 and was relatively stable. However, the increasing complexity of the implementation became an increasing problem as the compiler became large and slow. As a result, some features were removed from the official standard.

In autumn of the same year work began on a completely new implementation (only the parser , written in C and with the help of Yacc , was taken over), again with the assistance of SP Jones, as well as Cordelia Hall and Will Partain. Development was carried out entirely in Haskell; this was made possible by bootstrapping , in which the new compiler was first compiled with the old implementation until the new implementation could compile itself (self-hosting). In 1992 the first complete version was released, 0.10.

functionality

First, the Haskell code is parsed into a single data structure in order to perform type tests. Haskell is a very strongly typed language, which is why this step is very important (if there are no errors here, the probability that the program is error-free is very high).

After this first phase, the program is transformed into an intermediate language called Core . The core language (originally based on the lambda calculus ) has a very straightforward definition, which makes it easy to write routines that transform it, for example to optimize the program. The core language is one of the strengths of the GHC as it is a modular optimization architecture that can be easily customized.

An STG representation ( Spineless Tagless G-machine , an invention of Jones) is generated from the core form , from which C−− code is then first extracted, and finally in C - (now no longer), LLVM - or Machine code to be transferred. The resulting file is linked (mostly statically) against the GHC runtime system , which is written in C and C−−.

language

The GHC fully supports the two important Haskell standards Haskell 98 and Haskell 2010 . In addition, it implements many other extensions to the language and the type system.

service

Similar to the C compiler, GHC offers many language and warning options on the command line. It is also characterized by the ability to build entire programs using the option --make . Module dependencies are automatically taken into account and resolved, similar to make .

GHCi

GHCi is an interactive Haskell environment and part of GHC. It reads a Haskell expression, evaluates it and finally outputs the result. In addition, GHCi enables the compilation and loading of source code in order to test it, the integration of modules and the output of information about functions, type classes, data types and modules.

The following is an example session with reloading code, information about functions, instances and types etc .:

GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :l 1.hs
[1 of 1] Compiling Main             ( 1.hs, interpreted )
Ok, modules loaded: Main.
*Main> :i toDiffString
toDiffString :: [a] -> DiffString a     -- Defined at 1.hs:7:1
*Main> :i DiffString
newtype DiffString x = DiffString ([x] -> [x])
      -- Defined at 1.hs:4:9
instance Show x => Show (DiffString x) -- Defined at 1.hs:15:10
instance Monoid (DiffString x) -- Defined at 1.hs:18:10
*Main> fromDiffString . toDiffString $ "Hello World!"
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package mtl-2.1.2 ... linking ... done.
"Hello World!"
*Main> :k DiffString
DiffString :: * -> *
*Main>

criticism

Criticisms of the GHC that were frequently mentioned and confirmed in a survey in 2005 include its low speed, the error messages that are often difficult to decipher, the size and poor execution speed of the code generated and the size and confusion of the GHC source code.

Individual evidence

  1. Paul Hudak, John Hughes, Simon Peyton Jones, Philip Wadler: A History of Haskell: Being Lazy With Class , April 16, 2007
  2. git.haskell.org . (accessed on September 22, 2019).
  3. ghc --version
  4. a b Hudak, Paul, John Hughes, Simon Peyton Jones and Philip Wadler: A History of Haskell: Being Lazy With Class (2007). Proceedings of the Third ACM SIGPLAN History of Programming Languages ​​Conference (HOPL-III)
  5. Simon Peyton Jones: Compiling Haskell by program transformation: a report from the trenches (1996)
  6. GHC Survey ( Memento of the original from June 8, 2013 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / www.haskell.org