package rocq-runtime
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a45280ab4fbaac7540b136a6b073b4a6db15739ec1e149bded43fa6f4fc25f20
doc/rocq-runtime.pretyping/LibBinding/index.html
Module LibBindingSource
This file contain a lightweight API for meta-programming: to traverse binders and either keep them, create new ones.
With this API, variables are refered abstractly using access_key. For instance, to compute the term associated to a variable (debruijn variable) one should use get_term : acces_key -> constr t. Such terms can easily be created using the monadic bind: let* t = get_term k in ....
So that the users do not have to create access_key themselves, and make mistakes, the creation of access_key is directly handled by the functions creating binders. For instance, to create a product Prod A B, the body B has type access_key -> constr t where the access_key of the variable A. To easily write code, it recomended to use the notation let@: let@ key_A = make_binder naming na A in (* def of B : constr t *) .
It also provides facilities for naming variables, the different functions taking type naming_scheme = rel_declaration -> rel_declaration t as arguments. A few basic ones are provided.
To do so, the API uses a reader monad with a state that contains:
- the environment (Declarations + local context),
- the evar_map,
- the set of names already used,
- a substitution from the former context of the term being traversed, to the context of the term being created which may differ due to addition of new binders
Fold Functions for State
val fold_right_state :
('c -> 'b list -> 'b list) ->
'a list ->
(int -> 'a -> ('c -> 'd State.t) -> 'd State.t) ->
('b list -> 'd State.t) ->
'd State.tThis function is meant to iterate a function creating binders. 'c -> 'b list -> 'b list explains which access_key to save, e.g. :: to save them all.
val fold_left_state :
('c -> 'b list -> 'b list) ->
'a list ->
(int -> 'a -> ('c -> 'd State.t) -> 'd State.t) ->
('b list -> 'd State.t) ->
'd State.tThis function is meant to iterate a function creating binders: int -> 'a -> ('c -> 'd t) -> 'd t. 'c -> 'b list -> 'b list explains which access_key to save, e.g. :: to save them all.
val fold_right_state_3 :
('c -> 'b list -> 'b list) ->
'a list ->
(int -> 'a -> (('c * 'c * 'c) -> 'd State.t) -> 'd State.t) ->
(('b list * 'b list * 'b list) -> 'd State.t) ->
'd State.tThis function is meant to iterate a function creating binders. 'c -> 'b list -> 'b list explains which access_key to save, e.g. :: to save them all.
val fold_left_state_3 :
('c -> 'b list -> 'b list) ->
'a list ->
(int -> 'a -> (('c * 'c * 'c) -> 'd State.t) -> 'd State.t) ->
(('b list * 'b list * 'b list) -> 'd State.t) ->
'd State.tThis function is meant to iterate a function creating binders: int -> 'a -> ('c -> 'd t) -> 'd t. 'c -> 'b list -> 'b list explains which access_key to save, e.g. :: to save them all.
Naming Schemes for Binders
Identity namming
Name the binder using the head of the declaration's type if it Anonymous.
naming_dep if true, naming_id otherwise
Uses the next fresh names available, using the head of the declaration's type if it Anonymous.
naming_hd_fresh if true, naming_id otherwise
Functions on Terms
val ind_relevance :
Declarations.one_inductive_body ->
Evd.einstance ->
Evd.erelevance State.tval whd_decompose_prod_decls :
EConstr.constr ->
(EConstr.rel_context * EConstr.constr) State.tval eta_expand_instantiation :
EConstr.constr array ->
EConstr.rel_context ->
EConstr.constr array State.tval fresh_sort_ql :
?sort_rigid:bool ->
?name:Names.variable ->
Evd.rigid ->
(Sorts.QVar.t * Univ.Universe.t) State.tCreate a New Lambda, Product, or LetIn
Status of the variable to bind
Which binders to bind
val add_decl :
freshness ->
naming_scheme ->
EConstr.rel_declaration ->
(State.access_key -> 'a State.t) ->
'a State.tAdd a declaration to the state given its freshness and a naming_scheme, for a body defined in the updated state.
val build_binder :
((EConstr.constr -> EConstr.constr) -> 'a -> 'b) ->
binder ->
freshness ->
naming_scheme ->
EConstr.rel_declaration ->
(State.access_key -> 'a State.t) ->
'b State.tBind a declaration with binder or LetIn, given its freshness and a naming_scheme, for a body defined in the updated state.
val make_binder :
((EConstr.constr -> EConstr.constr) -> 'a -> 'b) ->
binder ->
naming_scheme ->
Names.Name.t EConstr.binder_annot ->
EConstr.types ->
(State.access_key -> 'a State.t) ->
'b State.tCreate a new binder using a naming_scheme, for a body in the updated state. When creating a fresh binder, the type of the variable needs to type check in the current context.
val keep_binder :
((EConstr.constr -> EConstr.constr) -> 'a -> 'b) ->
binder ->
naming_scheme ->
Names.Name.t EConstr.binder_annot ->
EConstr.types ->
(State.access_key -> 'a State.t) ->
'b State.tKeep a former binder using a naming_scheme, for a body defined in the updated state.
Create Lambda, Product, or LetIn for Context
val add_context :
freshness ->
naming_scheme ->
EConstr.rel_context ->
(State.access_key list -> 'a State.t) ->
'a State.tAdd a context to the state given its freshness and a naming_scheme, for a body defined in the updated state state * access_key list -> constr.
val add_context_sep :
freshness ->
naming_scheme ->
EConstr.rel_context ->
((State.access_key list * State.access_key list * State.access_key list) ->
'a State.t) ->
'a State.tAdd a context to the state given its freshness and a naming_scheme, for a body defined in the updated state, where the access_key are split between key_vars, key_letin, key_both.
val closure_context :
((EConstr.constr -> EConstr.constr) -> 'a -> 'a) ->
binder ->
freshness ->
naming_scheme ->
EConstr.rel_context ->
(State.access_key list -> 'a State.t) ->
'a State.tBind a context with binder or LetIn, given its freshness and a naming_scheme, for a body defined in the updated state.
val closure_context_sep :
((EConstr.constr -> EConstr.constr) -> 'a -> 'a) ->
binder ->
freshness ->
naming_scheme ->
EConstr.rel_context ->
((State.access_key list * State.access_key list * State.access_key list) ->
'a State.t) ->
'a State.tBind a context with binder or LetIn, given its freshness and a naming_scheme, for a body defined in the updated state, where the access_key are split between key_vars, key_letin, key_both.
val rebind :
((EConstr.constr -> EConstr.constr) -> 'a -> 'a) ->
binder ->
freshness ->
naming_scheme ->
EConstr.constr ->
((State.access_key list * State.access_key) -> 'a State.t) ->
'a State.tDecompose a constr as binder(s) local hd, then rebind it as binder(s) local, binder hd, cc
val read_by_decl :
EConstr.rel_context ->
(EConstr.rel_declaration ->
(State.access_key -> EConstr.constr State.t) ->
EConstr.constr State.t) ->
(int ->
State.access_key ->
(State.access_key list -> EConstr.constr State.t) ->
EConstr.constr State.t) ->
(int ->
State.access_key ->
(State.access_key list -> EConstr.constr State.t) ->
EConstr.constr State.t) ->
(State.access_key list -> EConstr.constr State.t) ->
EConstr.constr State.treads cxt binder cc_letin cc_var go through a context cxt, apply binder to each context declaration decl to it, then apply cc_letin if decl is a LetIn, and cc_var otherwise.
val get_args :
Declarations.mutual_inductive_body ->
Evd.einstance ->
(Constr.rel_context * Constr.t) ->
(EConstr.rel_context * EConstr.constr array) State.tGiven a mutual inductive body and an instance, it recovers the context of argument and the return indices of the constructor out of mind_nf_lc
val iterate_ctors :
Declarations.mutual_inductive_body ->
Declarations.one_inductive_body ->
Evd.einstance ->
(int ->
(EConstr.rel_context * EConstr.constr array) ->
('a -> 'b State.t) ->
'b State.t) ->
('a list -> 'b State.t) ->
'b State.tIterate a binding function to each constructor or an inductive type.
Functions on Inductives
val make_ind :
(Names.inductive * EConstr.EInstance.t) ->
State.access_key list ->
State.access_key list ->
State.access_key list ->
EConstr.constr State.tCreate a term refering to an inductive type given the access_key for uniform paramters, non-uniform parameters, and indices.
val make_cst :
(Names.inductive * EConstr.EInstance.t) ->
int ->
State.access_key list ->
State.access_key list ->
EConstr.constr array ->
EConstr.constr State.tCreate a term refering to the constructor of an inductive type given the access_key for uniform paramters, non-uniform parameters, and indices.
val make_fix :
'a list ->
int ->
(int -> 'a -> int) ->
(int -> 'a -> Names.Name.t EConstr.binder_annot) ->
(int -> 'a -> EConstr.types State.t) ->
((State.access_key list * int * 'a) -> EConstr.constr State.t) ->
EConstr.constr State.tCreate a term refering to an inductive type given the access_key for uniform paramters, non-uniform parameters, and indices.
val get_indices :
Declarations.one_inductive_body ->
Evd.einstance ->
EConstr.rel_context State.tRecover the indices of an inductive block, and weaken them in the current context.
val make_case_or_projections :
naming_scheme ->
Declarations.mutual_inductive_body ->
Names.inductive ->
Declarations.one_inductive_body ->
Evd.einstance ->
State.access_key list ->
State.access_key list ->
EConstr.constr array ->
EConstr.constr array ->
(State.access_key list -> State.access_key -> EConstr.types State.t) ->
Evd.erelevance ->
EConstr.constr ->
((State.access_key list * State.access_key list * State.access_key list * int) ->
EConstr.constr State.t) ->
EConstr.constr State.tCreate a new match given:
- A
naming_schemefor the fresh indices, and arguments - The
mutual_inductive_body,inductive,one_inductive_body,instanceon which the match is performed - The access keys for its uniform and non-uniform parameters
- The parameters
constr array, and indicesconstr arrayof the term being matched - The return type of the match
access_key list -> access_key -> constr t - The
relevanceof the match - The term being matched
constr