Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Glasgow Haskell Compiler
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Compiler for Haskell programming language}} {{Use dmy dates|date=February 2020}} {{Infobox software | title = The Glasgow Haskell Compiler | name= | logo = | logo caption = | screenshot = | caption = | author = Kevin Hammond | developer = [[Simon Marlow]], [[Simon Peyton Jones]], The Glasgow Haskell Team<ref name="contribs"/> | released = {{Start date and age|1992|12}}<ref name="history"/><!-- Work began in 1989, but the first public, non-beta release was in December 1992 --> | latest release version = {{wikidata|property|edit|P348}} | latest release date = {{Start date and age| {{wikidata|qualifier|P348|P577}} |df=y}}<ref> {{cite web |title=Download β The Glasgow Haskell Compiler |url=https://www.haskell.org/ghc/download.html |website=Haskell.org }} </ref> | latest preview version = | latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} --> | programming language = [[Haskell]], [[C (programming language)|C]] | operating system = [[Linux]], [[macOS Catalina]]<ref name=deprecate32bit>{{cite web|url=https://www.haskell.org/ghc/blog/20240613-32-bit-darwin-and-windows-deprecation.html|title=Deprecation of 32-bit Darwin and Windows platforms|publisher=GHC Team}}</ref> and later, [[Windows 2000]] and later, [[FreeBSD]] | platform = [[x86-64]],<ref name=deprecate32bit /> [[AArch64]] | size = | language = English | genre = [[Compiler]] | license = [[BSD licenses#3-clause|BSD 3-clause]] (new) | website = {{URL|www.haskell.org/ghc}} }} The '''Glasgow Haskell Compiler''' ('''GHC''') is a native or [[machine code]] [[compiler]] for the [[Functional programming|functional]] [[programming language]] [[Haskell]].<ref name="manual"> {{cite web | title = The Glorious Glasgow Haskell Compilation System User's Guide | url = https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/index.html | website = Haskell.org | access-date = 27 July 2014 }} </ref> It provides a [[cross-platform software]] environment for writing and testing Haskell code and supports many extensions, [[Library (computing)|libraries]], and optimisations that streamline the process of generating and executing code. GHC is the most commonly used Haskell compiler.<ref> {{cite web | title = 2017 state of Haskell survey results | url = http://taylor.fausak.me/2017/11/15/2017-state-of-haskell-survey-results/#question-14 | website = taylor.fausak.me | date = 15 November 2017 | access-date = 11 December 2017 }} </ref> It is [[free and open-source software]] released under a [[BSD licenses|BSD license]]. ==History== 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 analysis|strictness analyzer]] and language extensions such as [[Monads in functional programming|monadic I/O]], mutable arrays, unboxed data types, concurrent and parallel programming models (such as [[software transactional memory]] and [[data parallelism]]) and a [[Profiling (computer programming)|profiler]].<ref name="history"> {{cite conference | last1=Hudak |first1=P. |last2=Hughes |first2=J. |last3=Peyton Jones |first3=S. |author3-link=Simon Peyton Jones |last4=Wadler |first4=P. | date=June 2007 | title=A History of Haskell: Being Lazy With Class | book-title=Procedures of the Third ACM SIGPLAN History of Programming Languages Conference (HOPL-III) | url=https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/history.pdf | access-date=1 September 2016 }} </ref> 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.<ref name="contribs"> {{cite web | title = The GHC Team | url = https://gitlab.haskell.org/ghc/ghc/wikis/team-ghc | website = Haskell.org | access-date = 1 September 2016 }}</ref> From 2009 to about 2014, third-party contributions to GHC were funded by the Industrial Haskell Group.<ref> {{cite web | title = Industrial Haskell Group | url = http://industry.haskell.org | website = Haskell.org | date = 2014 | access-date = 1 September 2016 }} </ref> ===GHC names=== Since early releases the official website<ref>{{cite web |title=GHC The Glasgow Haskell Compiler |url=https://www.haskell.org/ghc/ |website=Haskell.org |access-date=14 January 2022}}</ref> 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''.<ref>{{cite web |title=Repository: configure.ac |url=https://gitlab.haskell.org/ghc/ghc/-/blob/c2a6c3eb380891eb44d30529f0b9f8f6debf31c9/configure.ac |website=gitlab.haskell.org |date=12 January 2022 |access-date=14 January 2022}}</ref> This has been reflected in the documentation.<ref>{{cite web |title=The Glorious Glasgow Haskell Compilation System User's Guide, Version 7.6.3 |url=https://downloads.haskell.org/~ghc/7.6.3/docs/html/users_guide/ |website=downloads.haskell.org |access-date=14 January 2022}}</ref> Initially, it had the internal name of ''The Glamorous Glasgow Haskell Compiler''.<ref>{{cite web |title=ghc-0.29-src.tar.gz |url=https://downloads.haskell.org/~ghc/0.29/ghc-0.29-src.tar.gz |format=[[tar (computing)|tar]] [[gzip]] |website=downloads.haskell.org |at=File: ghc-0.29/ghc/PATCHLEVEL |access-date=14 January 2022}}</ref> ==Architecture== GHC is [[Bootstrapping (compilers)|written in Haskell]],<ref> {{Cite web | url = https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler | title = GHC Commentary: The Compiler | website = Haskell.org | date = 23 March 2016 | access-date = 26 May 2016 | url-status = dead | archive-url = https://web.archive.org/web/20160323040632/https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler | archive-date = 23 March 2016 }} </ref> but the [[Run-time system|runtime system]] for Haskell, essential to run programs, is written in [[C (programming language)|C]] and [[C--]]. GHC's [[Compilers#Front end|front end]], incorporating the [[Lexical analysis|lexer]], parser and [[Type system|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.<ref name="history"/> After type checking, the Haskell code is [[Syntactic sugar|desugared]] into a typed [[intermediate language]] known as "Core" (based on [[System F]], extended with <code>let</code> and <code>case</code> 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 F<sub>C</sub>.<ref name="Sulzmann2007"> {{cite conference | last1 = Sulzmann | first1 = M. | last2 = Chakravarty | first2 = M. M. T. | last3 = Peyton Jones | first3 = S. |author3-link=Simon Peyton Jones | last4 = Donnelly | first4 = K. | date = January 2007 | title = System F with Type Equality Coercions | book-title = Procedures of the ACM Workshop on Types in Language Design and Implementation (TLDI) | url = https://www.microsoft.com/en-us/research/publication/system-f-with-type-equality-coercions/ }} </ref> In the tradition of type-directed compiling, GHC's simplifier, or "middle end", where most of the [[Compiler optimization|optimizations]] implemented in GHC are performed, is structured as a series of [[Source code|source-to-source]] [[Program transformation|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 [[Deforestation (computer science)|fusion]]), unfolding (called "[[inlining]]" in more traditional compilers), [[let-floating]], an analysis that determines which function arguments can be unboxed, [[constructed product result analysis]], [[Partial evaluation|specialization]] of [[Type class|overloaded]] functions, and a set of simpler local transformations such as [[constant folding]] and [[beta reduction]].<ref name="comp-by-trans"> {{cite conference | last = Peyton Jones | first = S. |author-link=Simon Peyton Jones | date = April 1996 | title = Compiling Haskell by program transformation: a report from the trenches | book-title = Procedures of the European Symposium on Programming (ESOP) | url = https://www.microsoft.com/en-us/research/publication/compiling-haskell-by-program-transformation-a-report-from-the-trenches/ }}</ref> 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").<ref name="stg"> {{cite journal | last = Peyton Jones | first = S. |author-link=Simon Peyton Jones | date = April 1992 | title = Implementing lazy functional languages on stock hardware: the Spineless Tagless G-machine, Version 2.5 | journal = Journal of Functional Programming | volume = 2 | issue = 2 | pages = 127β202 | url = https://www.microsoft.com/en-us/research/publication/implementing-lazy-functional-languages-on-stock-hardware-the-spineless-tagless-g-machine/ | doi = 10.1017/S0956796800000319 }}</ref> The C-- code can then take one of three routes: it is either printed as C code for compilation with [[GNU Compiler Collection|GCC]], converted directly into native machine code (the traditional "[[Code generation (compiler)|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. ==Language== GHC complies with the language standards, both ''Haskell 98''<ref name="h98"> {{cite web | title = Haskell 98 Language and Libraries: The Revised Report | url = https://www.haskell.org/onlinereport/ | website = Haskell.org | access-date = 28 January 2007 }} </ref> and ''Haskell 2010''.<ref name="h2010"> {{cite web | title = Haskell 2010 Language Report | url = https://www.haskell.org/onlinereport/haskell2010/ | website = Haskell.org | access-date = 30 August 2012 }} </ref> It also supports many optional extensions to the Haskell standard: for example, the [[software transactional memory]] (STM) library, which allows for [[Composable Memory Transactions]]. ===Extensions to Haskell=== 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<ref>{{cite web |title = Welcome to Haskell' (Haskell Prime) |url = https://prime.haskell.org |website = Haskell.org |access-date = 26 May 2016 |archive-date = 20 February 2016 |archive-url = https://web.archive.org/web/20160220103915/https://prime.haskell.org/ |url-status = dead }}</ref> to describe extensions and select those which will be included in future versions of the language specification. The extensions<ref>{{cite web | title = GHC Language Features | url = https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/lang.html | website = Haskell.org | access-date = 25 May 2016 | archive-date = 29 June 2016 | archive-url = https://web.archive.org/web/20160629143456/https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/lang.html | url-status = dead }}</ref> supported by the Glasgow Haskell Compiler include: * Unboxed types and operations. These represent the primitive datatypes of the underlying hardware, without the indirection of a pointer to the [[dynamic allocation|heap]] or the possibility of deferred evaluation. Numerically intensive code can be significantly faster when coded using these types. * The ability to specify [[strict evaluation]] for a value, pattern binding, or datatype field. * More convenient syntax for working with modules, patterns, [[list comprehension]]s, operators, records, and tuples. * [[Syntactic sugar]] for computing with [[arrow (functional programming)|arrows]] and recursively-defined [[Monad (functional programming)|monadic]] values. Both of these concepts extend the monadic {{mono|do}}-notation provided in standard Haskell. * A significantly more powerful system of types and typeclasses, described below. * [[Template Haskell]], a system for compile-time [[metaprogramming]]. Expressions can be written to produce Haskell code in the form of an [[abstract syntax tree]]. These expressions are typechecked and evaluated at compile time; the generated code is then included as if it were part of the original code. Together with the ability to [[Reflective programming|reflect]] on definitions, this provides a powerful tool for further extensions to the language. * Quasi-quotation, which allows the user to define new concrete syntax for expressions and patterns. Quasi-quotation is useful when a metaprogram written in Haskell manipulates code written in a language other than Haskell. * [[Generic programming|Generic]] typeclasses, which specify functions solely in terms of the algebraic structure of the types they operate on. * Parallel evaluation of expressions using multiple CPU cores. This does ''not'' require explicitly spawning threads. The distribution of work happens implicitly, based on annotations provided in the program. * Compiler [[Directive (programming)|pragmas]] for directing optimizations such as [[inline expansion]] and specializing functions for particular types. * Customizable rewrite rules are rules describing how to replace one expression with an equivalent, but more efficiently evaluated expression. These are used within core [[data structure]] libraries to improve performance throughout application-level code.<ref> {{cite conference | last1 = Coutts | first1 = D. | last2 = Leshchinskiy | first2 = R. | last3 = Stewart | first3 = D. | date = April 2007 | title = Stream Fusion: From Lists to Streams to Nothing at All | book-title = Procedures of the ACM SIGPLAN International Conference on Functional Programming (ICFP) | url-status = dead | url = http://www.cse.unsw.edu.au/~dons/papers/CLS07.html | archive-url = https://web.archive.org/web/20070923094030/http://www.cse.unsw.edu.au/~dons/papers/CLS07.html | archive-date = 23 September 2007 }} </ref> * Record dot syntax. Provides [[syntactic sugar]] for accessing the fields of a (potentially nested) record which is similar to the syntax of many other programming languages.<ref> {{cite web | last1 = Mitchell | first1 = Neil | last2 = Fletcher | first2 = Shayne | date = 3 May 2020 | title = Record Dot Syntax | url = https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0282-record-dot-syntax.rst | work = ghc-proposals | publisher = [[GitHub]] | access-date = 30 June 2020 }} </ref> ===Type system extensions=== 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 type]]s and [[type class]]es. The Glasgow Haskell Compiler supports an extended type system based on the theoretical System F<sub>C</sub>.<ref name="Sulzmann2007"/> Major extensions to the type system include: * [[Parametric polymorphism#Higher-ranked polymorphism|Arbitrary-rank]] and [[Parametric polymorphism#Impredicative polymorphism|impredicative]] [[Polymorphism (computer science)|polymorphism]]. Essentially, a polymorphic function or datatype constructor may require that one of its arguments is also polymorphic. * [[Generalized algebraic data type]]s. Each constructor of a polymorphic datatype can encode information into the resulting type. A function which pattern-matches on this type can use the per-constructor type information to perform more specific operations on data. * [[Existential type]]s. These can be used to "bundle" some data together with operations on that data, in such a way that the operations can be used without exposing the specific type of the underlying data. Such a value is very similar to an [[object (computer science)|object]] as found in [[object-oriented programming]] languages. * Data types that do not actually contain any values. These can be useful to represent data in type-level [[metaprogramming]]. * [[Type families]]: user-defined functions from types to types. Whereas parametric polymorphism provides the same structure for every type instantiation, type families provide ''ad hoc'' polymorphism with implementations that can differ between instantiations. Use cases include content-aware optimizing containers and type-level metaprogramming. * Implicit function parameters that have dynamic [[scope (programming)|scope]]. These are represented in types in much the same way as type class constraints. * [[Linear types]] (GHC 9.0) Extensions relating to [[type class]]es include: * A type class may be parametrized on more than one type. Thus a type class can describe not only a set of types, but an ''n''-ary [[finitary relation|relation]] on types. * [[Functional dependencies]], which constrain parts of that relation to be a mathematical [[function (mathematics)|function]] on types. That is, the constraint specifies that some type class parameter is completely determined once some other set of parameters is fixed. This guides the process of [[type inference]] in situations where otherwise there would be ambiguity. * Significantly relaxed rules regarding the allowable shape of type class instances. When these are enabled in full, the type class system becomes a [[Turing-complete]] language for [[logic programming]] at compile time. * Type families, as described above, may also be associated with a type class. * The automatic generation of certain type class instances is extended in several ways. New type classes for [[generic programming]] and common recursion patterns are supported. Also, when a new type is declared as [[isomorphic]] to an existing type, any type class instance declared for the underlying type may be lifted to the new type "for free". ==Portability== Versions of GHC are available for several system or [[computing platform]], including [[Microsoft Windows|Windows]] and most varieties of [[Unix]] (such as [[Linux]], [[FreeBSD]], [[OpenBSD]], and [[macOS]]).<ref name=platform>[https://gitlab.haskell.org/ghc/ghc/wikis/platforms ''Platforms'' at gitlab.haskell.org]</ref> GHC has also been [[Porting|ported]] to several different [[Processor design|processor architectures]].<ref name=platform/> ==See also== * [[Hugs (interpreter)]] * [[Yhc]] * [[Haskell Platform]] ==References== {{Reflist}} ==External links== * {{Official website|www.haskell.org/ghc}} {{Haskell programming}} {{DEFAULTSORT:Ghc}} [[Category:Cross-platform free software]] [[Category:Free and open source compilers]] [[Category:Free Haskell implementations]] [[Category:History of computing in the United Kingdom]] [[Category:Software using the BSD license]] [[Category:University of Glasgow]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite conference
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Haskell programming
(
edit
)
Template:Infobox software
(
edit
)
Template:Mono
(
edit
)
Template:Official website
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)