How are Haskell programs compiled and executed internally?

To compile and execute a programming language on stock hardware you need a number of things:

  • a compiler to translate your source language into assembly code executable by the native host
  • a support library (aka runtime) for primitive language services, such as memory management, IO and thread management. Things that must be leveraged from lower-level system services.

C, Java, and GHC Haskell are examples of such systems. In the case of GHC, the entire architecture is described here. The pieces are also described individually, and in detail.

  • 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.
  • The runtime services (aka “the GHC runtime”) are described over several papers:

    1. The multicore garbage collector with thread-local heaps
    2. How the garbage collector services work
    3. How multithreading works in GHC
    4. How laziness is implemented
    5. How the runtime calls code in foreign languages

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)