Original author(s) | Kevin Hammond |
---|---|
Developer(s) | Simon Marlow, Simon Peyton Jones, The Glasgow Haskell Team [1] |
Initial release | December 1992[2] |
Stable release | 9.8.1
/ 9 October 2023
[3] |
Repository | |
Written in | Haskell, C |
Operating system | Linux, OS X 10.7 Lion and later, Windows 2000 and later, FreeBSD |
Platform | x86, x86-64, ARM |
Available in | English |
Type | Compiler |
License | BSD New |
Website |
www |
The Glasgow Haskell Compiler (GHC) is a native or machine code compiler for the functional programming language Haskell. [4] It provides a cross-platform software environment for writing and testing Haskell code and supports many extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC is the most commonly used Haskell compiler. [5] It is free and open-source software released under a BSD license. The lead developers are Simon Peyton Jones and Simon Marlow.
GHC originally begun in 1989 as a prototype, written in Lazy ML (LML) by Kevin Hammond at the University of Glasgow. Later that year, the prototype was completely rewritten in Haskell, except for its parser, by Cordelia Hall, Will Partain, and Simon Peyton Jones. Its first beta release was on 1 April 1991. Later releases added a strictness analyzer and language extensions such as monadic I/O, mutable arrays, unboxed data types, concurrent and parallel programming models (such as software transactional memory and data parallelism) and a profiler. [2]
Peyton Jones, and Marlow, later moved to Microsoft Research in Cambridge, where they continued to be primarily responsible for developing GHC. GHC also contains code from more than three hundred other contributors. [1] Since 2009, third-party contributions to GHC have been funded by the Industrial Haskell Group. [6]
Since early releases the official website [7] has referred to GHC as The Glasgow Haskell Compiler, whereas in the executable version command it is identified as The Glorious Glasgow Haskell Compilation System. [8] This has been reflected in the documentation. [9] Initially, it had the internal name of The Glamorous Glasgow Haskell Compiler. [10]
GHC is written in Haskell, [11] but the runtime system for Haskell, essential to run programs, is written in C and C--.
GHC's
front end, incorporating the
lexer, parser and
typechecker, is designed to preserve as much information about the source language as possible until after
type inference is complete, toward the goal of providing clear error messages to users.
[2] After type checking, the Haskell code is
desugared into a typed
intermediate language known as "Core" (based on
System F, extended with let
and case
expressions). Core has been extended to support
generalized algebraic datatypes in its
type system, and is now based on an extension to System F known as System FC.
[12]
In the tradition of type-directed compiling, GHC's simplifier, or "middle end", where most of the optimizations implemented in GHC are performed, is structured as a series of source-to-source transformations on Core code. The analyses and transformations performed in this compiler stage include demand analysis (a generalization of strictness analysis), application of user-defined rewrite rules (including a set of rules included in GHC's standard libraries that performs foldr/build fusion), unfolding (called " inlining" in more traditional compilers), let-floating, an analysis that determines which function arguments can be unboxed, constructed product result analysis, specialization of overloaded functions, and a set of simpler local transformations such as constant folding and beta reduction. [13]
The back end of the compiler transforms Core code into an internal representation of C--, via an intermediate language STG (short for "Spineless Tagless G-machine"). [14] The C-- code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code (the traditional " code generation" phase), or converted to LLVM IR for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.
GHC complies with the language standards, both Haskell 98 [15] and Haskell 2010. [16] It also supports many optional extensions to the Haskell standard: for example, the software transactional memory (STM) library, which allows for Composable Memory Transactions.
Many extensions to Haskell have been proposed. These provide features not described in the language specification, or they redefine existing constructs. As such, each extension may not be supported by all Haskell implementations. There is an ongoing effort [17] to describe extensions and select those which will be included in future versions of the language specification.
The extensions [18] supported by the Glasgow Haskell Compiler include:
An expressive static type system is one of the major defining features of Haskell. Accordingly, much of the work in extending the language has been directed towards data types and type classes.
The Glasgow Haskell Compiler supports an extended type system based on the theoretical System FC. [12] Major extensions to the type system include:
Extensions relating to type classes include:
Versions of GHC are available for several system or computing platform, including Windows and most varieties of Unix (such as Linux, FreeBSD, OpenBSD, and macOS). [21] GHC has also been ported to several different processor architectures. [21]
Original author(s) | Kevin Hammond |
---|---|
Developer(s) | Simon Marlow, Simon Peyton Jones, The Glasgow Haskell Team [1] |
Initial release | December 1992[2] |
Stable release | 9.8.1
/ 9 October 2023
[3] |
Repository | |
Written in | Haskell, C |
Operating system | Linux, OS X 10.7 Lion and later, Windows 2000 and later, FreeBSD |
Platform | x86, x86-64, ARM |
Available in | English |
Type | Compiler |
License | BSD New |
Website |
www |
The Glasgow Haskell Compiler (GHC) is a native or machine code compiler for the functional programming language Haskell. [4] It provides a cross-platform software environment for writing and testing Haskell code and supports many extensions, libraries, and optimisations that streamline the process of generating and executing code. GHC is the most commonly used Haskell compiler. [5] It is free and open-source software released under a BSD license. The lead developers are Simon Peyton Jones and Simon Marlow.
GHC originally begun in 1989 as a prototype, written in Lazy ML (LML) by Kevin Hammond at the University of Glasgow. Later that year, the prototype was completely rewritten in Haskell, except for its parser, by Cordelia Hall, Will Partain, and Simon Peyton Jones. Its first beta release was on 1 April 1991. Later releases added a strictness analyzer and language extensions such as monadic I/O, mutable arrays, unboxed data types, concurrent and parallel programming models (such as software transactional memory and data parallelism) and a profiler. [2]
Peyton Jones, and Marlow, later moved to Microsoft Research in Cambridge, where they continued to be primarily responsible for developing GHC. GHC also contains code from more than three hundred other contributors. [1] Since 2009, third-party contributions to GHC have been funded by the Industrial Haskell Group. [6]
Since early releases the official website [7] has referred to GHC as The Glasgow Haskell Compiler, whereas in the executable version command it is identified as The Glorious Glasgow Haskell Compilation System. [8] This has been reflected in the documentation. [9] Initially, it had the internal name of The Glamorous Glasgow Haskell Compiler. [10]
GHC is written in Haskell, [11] but the runtime system for Haskell, essential to run programs, is written in C and C--.
GHC's
front end, incorporating the
lexer, parser and
typechecker, is designed to preserve as much information about the source language as possible until after
type inference is complete, toward the goal of providing clear error messages to users.
[2] After type checking, the Haskell code is
desugared into a typed
intermediate language known as "Core" (based on
System F, extended with let
and case
expressions). Core has been extended to support
generalized algebraic datatypes in its
type system, and is now based on an extension to System F known as System FC.
[12]
In the tradition of type-directed compiling, GHC's simplifier, or "middle end", where most of the optimizations implemented in GHC are performed, is structured as a series of source-to-source transformations on Core code. The analyses and transformations performed in this compiler stage include demand analysis (a generalization of strictness analysis), application of user-defined rewrite rules (including a set of rules included in GHC's standard libraries that performs foldr/build fusion), unfolding (called " inlining" in more traditional compilers), let-floating, an analysis that determines which function arguments can be unboxed, constructed product result analysis, specialization of overloaded functions, and a set of simpler local transformations such as constant folding and beta reduction. [13]
The back end of the compiler transforms Core code into an internal representation of C--, via an intermediate language STG (short for "Spineless Tagless G-machine"). [14] The C-- code can then take one of three routes: it is either printed as C code for compilation with GCC, converted directly into native machine code (the traditional " code generation" phase), or converted to LLVM IR for compilation with LLVM. In all three cases, the resultant native code is finally linked against the GHC runtime system to produce an executable.
GHC complies with the language standards, both Haskell 98 [15] and Haskell 2010. [16] It also supports many optional extensions to the Haskell standard: for example, the software transactional memory (STM) library, which allows for Composable Memory Transactions.
Many extensions to Haskell have been proposed. These provide features not described in the language specification, or they redefine existing constructs. As such, each extension may not be supported by all Haskell implementations. There is an ongoing effort [17] to describe extensions and select those which will be included in future versions of the language specification.
The extensions [18] supported by the Glasgow Haskell Compiler include:
An expressive static type system is one of the major defining features of Haskell. Accordingly, much of the work in extending the language has been directed towards data types and type classes.
The Glasgow Haskell Compiler supports an extended type system based on the theoretical System FC. [12] Major extensions to the type system include:
Extensions relating to type classes include:
Versions of GHC are available for several system or computing platform, including Windows and most varieties of Unix (such as Linux, FreeBSD, OpenBSD, and macOS). [21] GHC has also been ported to several different processor architectures. [21]