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.x
ande 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
, wheree1
must have typeBool
ande2
must have the same type ase3
. - There is the fixed point combinator:
fix f
, wheref
has typea -> a
. We can use this to define recursive functions.
The REPL uses commands prefixed with :
like in GHCi.
:eval
or:e
evaluates an expression and displays its type. This is also the default action of the REPL (if you just type an expression):step
or:s
uses small-step evaluation and displays all the reductions:type
or:t
displays the type of an expression:parse
or:p
displays the result of parsing (but not typechecking) the inputCtrl-D
to exit