package lambdapi

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Core.EnvSource

Scoping environment for variables.

Sourcetype env = (string * (Term.var * Term.term * Term.term option)) list

Type of an environment, used in scoping to associate names to corresponding variables and types. Note that it cannot be implemented by a map as the order is important. The structure is similar to Term.ctxt, a tuple (x,a,t) is a variable x, its type a and possibly its definition t. The typing environment x1:A1,..,xn:An is represented by the list xn:An;..;x1:A1 in reverse order (last added variable comes first).

Sourcetype t = env

pp ppf env prints the environment env on the formatter ppf (for debug).

Sourceval empty : env

empty is the empty environment.

Sourceval add : string -> Term.var -> Term.term -> Term.term option -> env -> env

add n v a t env extends the environment env by mapping the string n to (v,a,t).

Sourceval find : string -> env -> Term.var

find n env returns the variable associated to the variable name n in the environment env. If none is found, Not_found is raised.

Sourceval mem : string -> env -> bool

mem n env returns true iff n is mapped to a variable in env.

Sourceval to_prod : env -> Term.term -> Term.term

to_prod env t builds a sequence of products/lets whose domains are the variables of the environment env (from left to right), and whose body is the term t. By calling to_prod [(xn,an,None);⋯;(x1,a1,None)] t you obtain a term of the form Πx1:a1,..,Πxn:an,t.

Sourceval to_abst : env -> Term.term -> Term.term

to_abst env t builds a sequence of abstractions or let bindings, depending on the definition of the elements in the environment whose domains are the variables of the environment env (from left to right), and which body is the term t: to_abst [(xn,an,None);..;(x1,a1,None)] t = λx1:a1,..,λxn:an,t.

Sourceval vars : env -> Term.var array

vars env extracts the array of variables in env. Note that the order is reversed: vars [(xn,an);..;(x1,a1)] = [|x1;..;xn|].

Sourceval appl : Term.term -> env -> Term.term

appl t env applies t to the variables of env.

Sourceval to_terms : env -> Term.term array

to_terms env extracts the array of the variables in env and injects them in tbox. This is the same as Array.map mk_Vari (vars env). Note that the order is reversed: to_tbox [(xn,an);..;(x1,a1)] = [|x1;..;xn|].

Sourceval to_ctxt : env -> Term.ctxt

to_ctxt e converts an environment into a context.

Sourceval match_prod : Term.ctxt -> Term.term -> (Term.term -> Term.term option -> Term.binder -> 'a) -> 'a

match_prod c t f returns f a None b if t matches Prod(a,b), and f a d b if t matches LLet(a,d,b), possibly after reduction.

  • raises [Invalid_argument]

    if the whnf of t is not a product.

Sourceval of_prod : Term.ctxt -> string -> Term.term -> env * Term.term

of_prod c s t returns a tuple (env,b) where b is constructed from the term t by unbinding as much dependent products as possible in the head of t. The free variables created by this process, prefixed by s, are given (with their types) in the environment env (in reverse order). For instance, if t is of the form Πx1:a1, ⋯, Πxn:an, b, then the function returns b and the environment (xn,an); ⋯;(x1,a1).

Sourceval of_prod_nth : Term.ctxt -> int -> Term.term -> env * Term.term

of_prod_nth c n t returns a tuple (env,b) where b is constructed from the term t by unbinding n dependent products. The free variables created by this process are given (with their types) in the environment env (in reverse order). For instance, if t is of the form Πx1:a1, ⋯, Πxn:an, b then the function returns b and the environment (xn,an); ⋯;(x1,a1). n must be non-negative.

  • raises [Invalid_argument]

    if t does not evaluate to a series of (at least) n products.

Sourceval of_prod_using : Term.ctxt -> Term.var array -> Term.term -> env * Term.term

of_prod_using c xs t is similar to of_prod s c n t where n = Array.length xs except that it replaces unbound variables by those of xs.

  • raises [Invalid_argument]

    if t does not evaluate to a series of (at least) n products.

Sourceval names : env -> int Lplib.Extra.StrMap.t

names env returns the set of names in env.

Sourceval gen_valid_idopts : env -> string list -> Common.Pos.strloc option list

gen_valid_idopts env ids generates a list of pairwise distinct identifiers distinct from those of env to replace ids.

OCaml

Innovation. Community. Security.