Question

AFAIK GHC is the most common compiler today, but I also see, that some other ompilers are available too. Is GHC really the best choice for all purposes or may I use something else instead? For instance, I read that some compiler (forgot the name) does better on optimizations, but doesn't implements all extensions.

Was it helpful?

Solution

GHC is by far the most widely used Haskell compiler, and it offers the most features. There are other options, though, which sometimes have some benefits over GHC. These are some of the more popular alternatives:

Hugs - Hugs is an interpreter (I don't think it includes a compiler) which is fast and efficient. It's also known for producing more easily understood error messages than GHC.

JHC - A whole-program compiler. JHC can produce very efficient code, but it's not feature-complete yet (this is probably what you're thinking of). Note that it's not always faster than GHC, only sometimes. I haven't used JHC much because it doesn't implement multi-parameter type classes, which I use heavily. I've heard that the source code is extremely clear and readable, making this a good compiler to hack on. JHC is also more convenient for cross-compiling and usually produces smaller binaries.

UHC - The Utrecht Haskell Compiler is near feature-complete (I think the only thing missing is n+k patterns) for Haskell98. It implements many of GHC's most popular extensions and some original extensions as well. According to the documentation code isn't necessarily well-optimized yet. This is also a good compiler to hack on.

In short, if you want efficient code and cutting-edge features, GHC is your best bet. JHC is worth trying if you don't need MPTC's or some other features. UHC's extensions may be compelling in some cases, but I wouldn't count on it for fast code yet.

OTHER TIPS

  1. Haskell is informally defined as the language handled by GHC.
  2. GHC is the compiler of the Haskell platform.
  3. Trying to optimize your code with GHC may pay off more than switching to another compiler as you'll learn some optimization skills.
  4. There are many very useful extensions in GHC. I just can't see how to live without them.

So, for anything serious (e.g. non-academic, non-experimental, non-volatile or using many packages), the pragmatic choice is to go with GHC.

I think it's also worth mentioning nhc98. From the blurb on the homepage:

nhc98 is a small, easy to install, standards-compliant compiler for Haskell 98, the lazy functional programming language. It is very portable, and aims to produce small executables that run in small amounts of memory. It produces medium-fast code, and compilation is itself quite fast. It also comes with extensive tool support for automatic compilation, foreign language interfacing, heap and time profiling, tracing, and debugging.

As of 2011, there's really no other choice than GHC for everyday programming. The HP team strongly encourages the use of GHC by all Haskell programmers.


If you're a researcher, you might use be using UHC, if you're on a very strange system, you might have only Hugs or nhc98 available. If you're a retro-fan like me, you still have gofer, hbc and hbi installed:

$ hbi
Welcome to interactive Haskell98 version 0.9999.5c Pentium 2004 Jun 29!
Loading prelude... 1 values, 4 libraries, 200 types found.
Type "help;" to get help.
> help;
        HBI  -- Interactive Haskell B 1.3

hbi is cool because a) it implements Haskell B, and b) it supports the full language at the command line:

> data L a = I | X a (L a) deriving Show;
data L b = I | X b (L b) deriving (Show)
> X 4 (X 3 I);
X 4 (X 3 I)

and the compiler produces pretty good code, even 15 years later.

ghc is a solid compiler. saying it is the best choice for all purposes is a very strong one. and looking for such a tool is futile.

Use it, and if you really require something else then by that point you'll probably know what it is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top