Glasgow Haskell Compiler facts for kids
Original author(s) | Kevin Hammond |
---|---|
Developer(s) | Simon Marlow, Simon Peyton Jones, The Glasgow Haskell Team |
Initial release | December 1992 |
Stable release | |
Written in | Haskell, C |
Operating system | Linux, macOS Catalina and later, Windows 2000 and later, FreeBSD |
Platform | x86-64, AArch64 |
Available in | English |
Type | Compiler |
License | BSD 3-clause (new) |
The Glasgow Haskell Compiler (GHC) is a special computer program. It takes code written in the Haskell programming language and turns it into instructions a computer can understand. This process is called compiling. GHC helps programmers write and test Haskell code. It works on many different types of computers and operating systems.
GHC is the most popular compiler for Haskell. It is also free and open-source software, which means anyone can use it and even help improve it.
Contents
History of GHC
The idea for GHC started in 1989. A person named Kevin Hammond at the University of Glasgow created an early version. Later that year, the program was mostly rewritten in Haskell itself. Cordelia Hall, Will Partain, and Simon Peyton Jones worked on this new version.
The first test version of GHC came out on April 1, 1991. Over time, new features were added. These features helped programmers write code that could do things like handle input and output, work with changing data, and even run parts of a program at the same time.
Simon Peyton Jones and Simon Marlow, who were key developers, later moved to Microsoft Research. They continued to lead the development of GHC. Many other people have also helped build GHC over the years.
How GHC Works
GHC is mostly written in Haskell, the language it compiles. However, some parts that help programs run are written in the C language.
When you give GHC Haskell code, it works in a few steps:
- Reading the Code: First, GHC reads your Haskell code. It checks for any basic mistakes and makes sure the code follows Haskell's rules. This helps give clear error messages if something is wrong.
- Making it Faster: Next, GHC tries to make your code run as fast and efficiently as possible. It does this by changing the code in smart ways without changing what it does. This step is where many optimizations happen.
- Turning into Computer Language: Finally, GHC turns the optimized Haskell code into machine code. This is the language your computer's processor understands directly. This machine code is then linked with other necessary parts to create a program that you can run.
Haskell Language and GHC
GHC follows the official rules for the Haskell language, including Haskell 98 and Haskell 2010. It also supports many extra features, called "extensions." These extensions give programmers more tools and ways to write code.
Extra Features in Haskell
Many extensions have been added to Haskell through GHC. These features go beyond the basic language rules. They help programmers do more advanced things or write code in easier ways.
Some of these extensions include:
- Faster Data Types: These help make programs that do a lot of math or calculations run much faster.
- Controlling How Code Runs: Programmers can tell GHC to run certain parts of their code in a specific order.
- Easier Ways to Write Code: Some extensions provide simpler ways to write common programming patterns, making the code cleaner and easier to read.
- Code That Writes Code: There are tools that let programmers write code that can create other Haskell code automatically. This is like having a helper that writes parts of your program for you.
- Using Multiple Processors: GHC can help programs use more than one part of your computer's processor at the same time. This makes complex programs run much faster without extra effort from the programmer.
- Hints for Optimization: Programmers can give GHC hints to help it make their code even faster.
- Smart Code Replacements: GHC can use special rules to replace parts of your code with more efficient versions. This helps improve how well programs perform.
- Easier Data Access: A feature called "record dot syntax" makes it simpler to get information from structured data, similar to how it's done in many other programming languages.
Advanced Type System Features
Haskell is known for its "type system," which helps catch errors in code before it even runs. GHC has made this system even more powerful. It helps programmers write code that is less likely to have mistakes.
For example, the type system can:
- Help bundle data with the actions that can be performed on that data. This is similar to how "objects" work in other programming languages.
Where GHC Works
GHC can be used on many different computer systems. This includes Windows and most types of Unix-like systems, such as Linux, FreeBSD, and macOS. GHC has also been adapted to work on various types of computer processors.
See also
- Hugs (interpreter)
- Haskell Platform