Module Mini_ml_lib.Interpreter

type error =
  1. | InvalidApplication
    (*

    When application is not valid

    *)
  2. | InvalidLet
    (*

    When recursive let statement is used wrongly

    *)
  3. | UnboundVariable of Ast.name
    (*

    When provided name is not a variable

    *)
  4. | TypeMismatch of string
    (*

    When type is invalid

    *)
  5. | TypesMismatch of string * string
    (*

    When pair of types is invalid

    *)

Type for interpreter's error

type 'a result =
  1. | Eval of 'a
  2. | EvalRaise of string
  3. | EvalError of error

Type for evaluation result

type step_limit =
  1. | Unlimited
    (*

    Count of steps is not bounded

    *)
  2. | Limited of int
    (*

    Count of steps is bounded and how many steps remaining

    *)

Type for step limit

type value =
  1. | Unit
  2. | Int of int
  3. | Bool of bool
  4. | Tuple of value * value * value list
  5. | Exception of string
  6. | Closure of Ast.t * env
  7. | BuiltinAbstraction of value -> value result

Type for interpreter's evaluated value

and env = (Ast.name * value) list * step_limit

Type for interpreter's enviropment

val new_env : env

Returns empty enviropment with built-in functions

val new_env_limited : int -> env

Returns empty enviropment with steps limit and built-in functions

val run : env -> Ast.t -> env * value result

Runs the interpreter

val show_result : value result -> string

Shows result in human-readable format

val show_error : error -> string

Shows error in human-readable format