exception Unimplemented exception SyntaxError type const = Num of int | String of string | Bool of bool | Unit | Nil type typ = TInt | TString | TBool | TUnit | TList of typ | TArrow of typ * typ | TProd of typ * typ | TVar of string (* Type variables like 'a *) | TUVar of int (* Unification variables like ?0 *) (* Don't worry about this *) type schema = SMono of typ | SForall of string * schema (* Infix operators *) type binop = Plus | Minus | Times | Div | Lt | Le | Gt | Ge | Eq | Ne | And | Or | Concat type unop = Neg | Not type var = string (* Don't worry about this either, it's used for building contexts *) module S = struct type t = var let compare = String.compare end module VMap = Map.Make(S) (* Expressions *) type expr = | EVar of var | EConst of const | EBinop of expr * binop * expr | EUnop of unop * expr | EFun of string * expr (* fun x -> e *) | EIf of expr * expr * expr (* if e1 then e2 else e3 *) | ELet of string * expr * expr (* let x = e1 in e2 *) (* let (rec?) f x = e1 in e2 *) | ELetFun of bool * string * string * expr * expr | ELetPair of string * string * expr * expr (* let (x, y) = e1 in e2 *) | EApp of expr * expr (* match e1 with | [] -> e2 | h::t -> e3 *) | EMatchList of expr * expr * string * string * expr | EPair of expr * expr | ECons of expr * expr (* Values are now only used as the result of evaluation. *) type value = VConst of const | VPair of value * value | VCons of value * value | VClos of string * expr * env and env = (var * value option ref) list type decl = | DVal of string * expr (* let x = e;; *) (* let (rec?) f x = e1;; *) | DFun of bool * string * string * expr (* e;; *) | DExp of expr let var_of_decl d = match d with | DVal (x, _) -> x | DFun (_, f, _,_) -> f | DExp _ -> "-" (* A program is a list of declarations *) type prog = decl list