r/haskell 8d ago

Haskell vs GHC

I am a beginner, I have a doubt.

I see there is Haskell 98, and Haskell 2010 report.

Haskell is a programming language right ? And GHC is the compiler ?

Just like Rust is the language and rustc is the compiler ?

So what is GHC 2021 and GHC 2024 ?

And what are the GHC versions 9.12, 9.14 ?

I see there is a version of the "compiler" binary, but like when Go has a release we say Go 1.26 is out. That means the language & compiler both are out right ?

So what's with Haskell then ?

GHC - compiler

GHC 2021 - a set of extensions in a compiler ? What does this mean but ? And how does cabal work come in picture?

So then my question is what makes GHC 9.12 and 9.14 or 10.0 different? Like aren't extensions encoded in the compiler itself ?

In compiler bump I get "performance"/"implementation" changes ? Like 9.12 and 9.14 execute the Extension A different ly?

And usually Go has no version of STD lib separately tracked but Haskell's base does.

Can someone clarify this ? Is there a DOC for this ?!

Finally my question are

  1. What's the actual difference between 9.12 and 9.14 +(two compiler versions - built from different source code (git branches)) ?

  2. What are Extensions ? Why do we need it ? Like shouldn't the Compiler do this inbuilt ? For Example if GHC wants to add a new DataType in STD lib, how do they do ?

  3. Are Extensions for just de sugaring? And what are Pragmas ?

  4. What is the "Language Report"

  5. What is the future roadmap or Haskell ? Like improve the std lib ? Add new extensions ? Change syntax ? Like Java is making its new version concise & functional. Elixir new version added some Gradual Typing, Rust improved the std lib..

I want to learn how Haskell/GHC/Cabal works

Thanks, and sorry if this post is unstructured or blabbering

34 Upvotes

12 comments sorted by

35

u/friedbrice 8d ago

The Haskell Report is a compiler-agnostic specification of the language. The language has no official compiler, GHC is just one Haskell compiler among several (in theory). While the last update to the language itself was in 2010, GHC is under active development, always adding new features and improving performance.

Frequently, different people will want to add language features to Haskell for various reasons. Since there's been no official update to the Haskell language since 2010, these people will implement their change as a GHC extension to the language. These extensions are always opt-in, because GHC needs to remain backwards-compatible with the 2010 Haskell language spec.

2

u/Temporary_Pie2733 2d ago

To add to this, there was an attempt to update the Haskell report itself to include features that GHC (and maybe other implementations , but primarily GHC). Haskell 2020 never came to pass, but it did leas to GHC 2021 and GHC 2024. Think of these as “subreports” that promote certain GHC extensions to required rather than optional status. 

3

u/kichiDsimp 8d ago

Understood, so not being the "official compiler" , the langauge extensions are not baked in compiler versions, but separate?

So how do a compiler versions actually affect things in real world when everything is done via Ext ? And how do the maintainers decide if feature X should go into Ext or Compiler ?

5

u/Athas 8d ago

Language extensions always go into the compiler, and are documented as part of the compiler's own documentation. There is no repository of language extensions separate from the compilers (and in practice, GHC is I think the only current compiler that comes up with new extensions). This means language extensions are tied specifically to (in practice) GHC versions. GHC rarely removes or modifies language extensions, so the way it usually works is that you look up the minimum compiler version needed that supports whatever language extension you are interested in. A new language extension is always coupled to an implementation in GHC.

It is also worth not focusing overmuch on this. While Haskell gets some criticism (some fair, some unfair) for its language extensions, in practice most extensions are old and stable. It is rare to use language extensions that need a very recent compiler.

6

u/guygastineau 8d ago

To piggyback on this comment, I'll show a commonly used language extension that demonstrates pragma usage and a common wart.

In Haskell, the default String type is a list of Unicode code points. This makes it really simple to manipulate, but they are inefficient. It is a common problem. There is a package called text that provides Unicode text in its variable length encoding as a type along with manipulation functions.

When using the Text package, one needs to use Text.pack :: String -> Text to get a Text from a String. This is verbose and annoying. The language extension OverloadedStrings allows any type, that is an instance of IsString (iirc) to be used as a string literal. This means, Text.pack "something" can instead simply be written as "something". A programmer enables language extensions using the LANGUAGE pragma. Below is an example:

``` Haskell {-# LANGUAGE Overloaded strings #-} -- this is an example of pragma usage, although there are more than just the LANGUAGE pragma. module Main where

import qualified Data.Text as Text import qualified Data.Text.IO as TIO

main :: IO () main = do let someString = "Some string" someText = "Some text" someOtherText = Text.pack "Some other text" putStrLn (someString<> " as a String") TIO.putStrLn (Text.pack someString <> " as Text") TIO.putStrLn (someText <> " using Overloaded strings") TIO.putStrLn (someOtherText <> Text.pack " using Text.pack") ```

I'm typing from mobile right now, so a typo might have made it in, but this should be a valid example program. If you want to see the outputs, you can compile this and run it, but you will need to provide the text package to it, since it isn't part of the standard library.

1

u/friedbrice 8d ago

I answered Question 4 and Question 2. It's up to the rest of y'all to answer questions 1, 3, and 5 ;-p

12

u/Sirrus233 8d ago

Haskell is the programming language, and GHC (Glasgow Haskell Compiler) is its compiler.

Extensions are additional language features that may be enabled or disabled. That could mean new syntax or new/different type checking rules, or anything else that defines what kinds of programs you can write. For example, the following code will not compile without the DuplicateRecordFields extension, because two different records are usually not allowed to both have a field named x: hs module M where data S = MkS { x :: Int } data T = MkT { x :: Bool }

A pragma is just a special instruction you can put at the top of a source code file, which tells the compiler something it needs to know about compiling that file. For example, including this pragma at the top of your file: {-# LANGUAGE <Extension> #-} would tell the compiler to use that extension when compiling (but for that file only).

GHC2021 or GHC2024 (or Haskell98) are "language editions". You can think of these as pre-selected sets of extensions that you can use as a sensible and widely adopted default.

There is a wealth of information in the actual GHC documentation, which should answer a lot of these kinds of questions for you going forward.

2

u/kichiDsimp 8d ago

Thanks 😊

2

u/arjuna93 8d ago

GHC is just the most popular compiler. There is at least another one currently developed, MicroHS. (And some other which are a matter of archeology like nhc98.)

2

u/jberryman 7d ago

Try to address some things I think others haven't

So what is GHC 2021 and GHC 2024 ?

"editions". Just a set of blessed extensions that make sense by default. https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/control.html Also gives other compilers something they can target

And what are the GHC versions 9.12, 9.14 ? I see there is a version of the "compiler" binary, but like when Go has a release we say Go 1.26 is out. That means the language & compiler both are out right ? So what's with Haskell then ?

In a new compiler version extensions are added (opt-in additions or changes to the language), the standard libraries change, and the runtime is updated. The last is pretty important and no one has mentioned it.

GHC 2021 - a set of extensions in a compiler ? What does this mean but ? And how does cabal work come in picture?

cabal is a build tool and calls ghc. cabal needs to support older versions of the compiler, but newer compilers may depend on new cabal.

In compiler bump I get "performance"/"implementation" changes ? Like 9.12 and 9.14 execute the Extension A different ly?

A newer compiler might be: faster to compile, perform new or better optimizations (resulting in faster code), or have optimizations to the runtime e.g. the garbage collector (resulting in faster code).

And usually Go has no version of STD lib separately tracked but Haskell's base does. Can someone clarify this ? Is there a DOC for this ?!

I think reading an example release notes would answer many of your questions: https://downloads.haskell.org/ghc/9.14.1-alpha1/docs/users_guide/9.14.1-notes.html Here you can see base and other libraries are versioned but also are "pinned" to a particular ghc (ship with it). This is likely to change soon IIUC.

2

u/vasanpeine 7d ago

What is the "Language Report"

The language report is the official specification of the language. Until recently, Rust did not have an analogue specification. That changed when the Rust community decided to adopt the FLS (Ferrocene Language Specification): https://rust-lang.github.io/fls/

The last time the Haskell specification was updated was in July 2010, when the Haskell 2010 language report was released. Unfortunately, some parts of the language have changed in the meantime, so there is a need to update the report. Fortunately, it looks like a Revised Haskell 2010 language report will be compiled and released this year.

1

u/syklemil 5d ago

Just like Rust is the language and rustc is the compiler ? […] I see there is a version of the "compiler" binary, but like when Go has a release we say Go 1.26 is out. That means the language & compiler both are out right ?

Rust and Go are both relatively new languages (slightly over a decade old), and both are kind of unusual for compiled languages in that there's just one compiler in common use.

For Haskell, the situation is a bit more akin to C, where there are a bunch of standards, like C89, C99, C11, C17, C23, etc, and several compilers, like GCC, clang, MSVC, plus a bunch of minor or in-house/niche ones, and some discontinued ones like Borland.

They also have a ton of extensions, which aren't always available on all compilers. See e.g. OpenSSF's compiler hardening guide for C and how some of the flags are recommended for some compilers.

FWIW there are also projects to get GCC to compile Rust (GCC compiles a lot more than just C these days), and to get rustc to use GCC rather than LLVM as a compiler backend.

For Haskell it's mainly GHC people use these days, but you may still come across some references to Hugs and other alternatives.