Module Common.Env

Environment

This module provides a simple environment data structure for storing bindings between keys and values. The environment supports adding and removing scopes, binding values to keys, and finding values bound to keys.

exception Not_found of string

Not_found id is raised when a binding for id is not found

exception Empty_env

Empty_env is raised when an operation is performed on an empty environment

exception Duplicate_binding of string

Duplicate_binding id is raised when a binding for id already exists

type 'a env =
  1. | Empty
  2. | Scope of (string * 'a) list * 'a env
val empty_env : 'a env

empty_env returns an empty environment with no bindings

  • returns

    an empty environment

val begin_scope : 'a env -> 'a env

begin_scope env returns a new environment with an empty scope

  • parameter env

    the environment to add a new scope to

  • returns

    a new environment with an empty scope

val end_scope : 'a env -> 'a env

end_scope env returns the environment without the last scope

  • parameter env

    the environment to remove the last scope from

  • returns

    the environment without the last scope

val bind : string -> 'a -> 'a env -> 'a env

bind x v env binds the value v to the key x in the environment env

  • parameter x

    the key to bind the value to

  • parameter v

    the value to bind to the key

  • parameter env

    the environment to bind the value to the key

  • returns

    the environment with the value bound to the key

val bind_at_depth : string -> 'a -> int -> 'a env -> 'a env

bind_at_depth x v n env binds the value v to the key x in the nth scope of the environment env

  • parameter x

    the key to bind the value to

  • parameter v

    the value to bind to the key

  • parameter n

    the depth of the scope to bind the value in

  • parameter env

    the environment to bind the value to the key

  • returns

    the environment with the value bound to the key

val find_flat : string -> 'a env -> 'a option

find_flat x env returns the value bound to the key x in the environment env

  • parameter x

    the key to find the value for

  • parameter env

    the environment to find the value in

  • returns

    the value bound to the key

val get : string -> 'a env -> 'a

get x env returns the value bound to the key x in the environment env

  • parameter x

    the key to find the value for

  • parameter env

    the environment to find the value in

  • returns

    the value bound to the key

val flatten : 'a env -> (string * 'a) list

flatten env returns a list of all the bindings in the environment env

  • parameter env

    the environment to flatten

  • returns

    a list of all the bindings in the environment

val string_of_env : ('a -> string) -> 'a env -> string

string_of_env v_fmt env returns a string representation of the environment env

  • parameter v_fmt

    the function to format the values in the environment

  • parameter env

    the environment to format

  • returns

    a string representation of the environment