Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilers for Haskell

Tags:

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.

like image 213
fuz Avatar asked Nov 03 '10 06:11

fuz


People also ask

Does Haskell have a compiler?

The compiler (written in Haskell), translates Haskell to C, assembly, LLVM bitcode and other formats. The strategy it uses is described best here: Implementing lazy functional languages on stock hardware:the Spineless Tagless G-machine.

Is Haskell good for compilers?

Haskell, with its support for pattern matching on data structures, generic structure traversals, and expressive type system, is popular for implementing compilers and interpreters.

Is Haskell built on C?

GHC itself is written in Haskell, but the runtime system for Haskell, essential to run programs, is written in C and C--.

Is Haskell compiler or interpreter?

Getting started. Like some languages Haskell can be both compiled and interpreted. The most widely used implementation of Haskell currently is GHC, which provides both an optimising native code compiler, and an interactive bytecode interpreter.


1 Answers

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.

like image 91
John L Avatar answered Oct 05 '22 08:10

John L