This program can:
- Take an untyped AST (
UTerm) which is easy to parse, for a little language that has bools, strings, lambdas, if and pure/bind. - By type checking it, convert it into a well-typed GADT.
- That well-typed GADT can then be trivially interpreted via
evalwhich is total. - It's easy to add functions of N-arity by adding a
PrimNconstructor.
An example program which features using IO to check whether a file exists and then writing a file depending on that condition, is at the end.
The type-checker just throws an error via error or a pattern match failure, but that's trivial to turn into an Either. The eval, however, throws no errors. (Although I/O code produced by it may, obviously.)