A simple Lambda calculus implementation with type inference.
A Lambda calculus type.
A Lambda calculus expression.
An error from parsing or evaluation.
evaluate : Expr -> Result Error ( Expr, Type )
Evaluates an expression and returns either an (Expr, Type)
pair, or an Error
.
import Lambda
-- Builtin values
evaluate (Int 42) --> Ok (Int 42, IntType)
evaluate (Num 3.14) --> Ok (Num 3.14, NumType)
-- Variable: x
evaluate (Var "x") --> Err (VariableNotFound "x")
-- Abstraction: λx.x
evaluate (Abs "x" (Var "x")) --> Ok (Abs "x" (Var "x"), AbsType (Type "a") (Type "a"))
-- Application: (λx.x) 42
evaluate (App (Abs "x" (Var "x")) (Int 42)) --> Ok (Int 42, IntType)