[Haskell-cafe] C++ Haskell interpreter with GADTs + Type Families + Rank-n types

Benjamin Redelings benjamin.redelings at gmail.com
Fri Jan 20 01:40:57 UTC 2023

Hi all,

I don't want to oversell this, but in case anyone is interested, I've 
been working on a Haskell interpreter that is written in C++.  This 
isn't intended to compete with GHC.  It doesn't generate machine code, 
and it is not fast.

However, I had a reason to try and implement Haskell typechecking in 
C++.  So if anyone is interested in how to write their own Haskell 
compiler, then this might possibly be of interest. Otherwise, probably not.

So far I have:

1. Parser

2. Renamer - hacky.  Infix handling is a separate pass.

3. Typechecker - standard constraints + rank n types + GADTS + type 
families.  But no newtypes and no coercions.

4. Desugarer - the desugarer generates a language w/o type-level lambdas 
or coercions.

5. Optimizer - inlining, let-floating, case-of-case, etc.  No 
SpecConstr.  No Rules.

6. Translation to de-Bruijn notation prior to execution (See Sestoft 
1997, "Deriving a lazy abstract machine")

7. Interpreter - a special-purpose dependency-tracking interpreter.

The revelant code is here: 

After compiling the executable, you would run use it to run a Haskell 
program like this:

     bali-phy --run-module Main.hs

Tests are in: 


More information about the Haskell-Cafe mailing list