GHC
By the Glasgow Haskell Compiler team
GHC (Glasgow Haskell Compiler) is the primary compiler and runtime system for the Haskell programming language, translating Haskell source into optimized native machine code and providing the lazy-evaluation runtime, garbage collector, and…
Definition
GHC (Glasgow Haskell Compiler) is the primary compiler and runtime system for the Haskell programming language, translating Haskell source into optimized native machine code and providing the lazy-evaluation runtime, garbage collector, and lightweight concurrency support that Haskell programs depend on. It is both a compiler and the de facto reference implementation that defines much of Haskell's practical behavior beyond the language standard.
Overview
Haskell is defined by a language report, but in practice GHC is what most developers mean when they say "Haskell," because it has long been the dominant implementation and has driven most of the language's real-world evolution through extensions that later influenced or became part of the standard. GHC's job is to compile a purely functional, lazily evaluated language down to efficient machine code, which is a harder problem than compiling a strict, imperative language because the compiler must reason about when computations actually need to happen rather than assuming code executes in the order it is written. Mechanically, GHC compiles Haskell through several intermediate languages, most notably Core, a small, explicitly typed functional language that GHC's many optimization passes operate on, including strictness analysis (determining where lazy evaluation can be safely skipped for performance), inlining, and specialization of polymorphic functions for concrete types. The compiled output runs on the GHC runtime system (RTS), which implements Haskell's default lazy evaluation through thunks (deferred computations), manages a generational garbage collector tuned for functional allocation patterns, and provides lightweight "green thread" concurrency that can run tens of thousands of concurrent Haskell threads over a small pool of OS threads. GHC's laziness-by-default and its runtime's approach to concurrency distinguish it sharply from compilers for strict functional or imperative languages like OCaml's or Rust's; laziness enables elegant infinite-data-structure idioms and better composability in some cases, but it also introduces its own class of performance pitfalls, like unintended thunk buildup, that GHC's strictness analysis and language extensions (such as `BangPatterns` or `-XStrict`) exist specifically to address. Among Haskell implementations, GHC is essentially unrivaled in maturity and adoption; alternative or historical Haskell compilers exist mainly for research or specialized targets, not as everyday competitors. In practice, developers build Haskell projects with GHC through the Stack or Cabal build tools, which invoke GHC with the correct package and extension flags; GHC itself also ships an interactive REPL, GHCi, widely used for exploratory development. GHC's extension system, dozens of opt-in language extensions enabled per file, lets Haskell code opt into advanced type-system features like GADTs, type families, and multi-parameter type classes well beyond the base language report, which is a major reason GHC-flavored Haskell in practice looks more feature-rich than the formal Haskell standard. The trade-offs are compile times, which can be substantial on codebases using heavy type-level programming, and the aforementioned laziness pitfalls, where a program can build up unevaluated thunks and consume more memory than an equivalent strict program unless the developer explicitly manages strictness. Teams accept these costs for GHC's strong static type guarantees, expressive type system, and the correctness benefits of a purely functional core.
Key Features
- Compiles Haskell through the Core intermediate language with heavy optimization
- Implements lazy evaluation via thunks in its runtime system
- Provides lightweight, cooperatively scheduled Haskell threads (green threads)
- Includes a generational garbage collector tuned for functional workloads
- Ships GHCi, an interactive REPL for exploratory Haskell development
- Supports dozens of opt-in language extensions beyond the Haskell standard
- Performs strictness analysis to reduce unnecessary lazy evaluation overhead
- Drives much of the practical evolution of the Haskell language itself