Implementation of simply typed lambda calculus, using GADTs achieve a representation of well-typed terms.
Inspired by this talk by Richard Eisenberg.
Run
cabal configure
cabal build
Then run cabal run gadt-STLC
The language is just simply-typed lambda calculus with recursion.
- The only types are
Int,Bool, andt -> t - There are integer constants and the operations
+,-,==,<,> - There are lambda abstractions and applications:
lam x:Int.xande e. You must annotate the type of all lambdas - There are let expressions:
let x = e in e - There are if expressions:
if e1 then e2 else e3, wheree1must have typeBoolande2must have the same type ase3. - There is the fixed point combinator:
fix f, wherefhas typea -> a. We can use this to define recursive functions.
The REPL uses commands prefixed with : like in GHCi.
:evalor:eevaluates an expression and displays its type. This is also the default action of the REPL (if you just type an expression):stepor:suses small-step evaluation and displays all the reductions:typeor:tdisplays the type of an expression:parseor:pdisplays the result of parsing (but not typechecking) the inputCtrl-Dto exit