1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(*i $Id: evarutil.mli 12053 2009-04-06 16:20:42Z msozeau $ i*)
22
(*s This modules provides useful functions for unification modulo evars *)
24
(***********************************************************)
27
(* [new_meta] is a generator of unique meta variables *)
28
val new_meta : unit -> metavariable
29
val mk_new_meta : unit -> constr
31
(* [new_untyped_evar] is a generator of unique evar keys *)
32
val new_untyped_evar : unit -> existential_key
34
(***********************************************************)
35
(* Creating a fresh evar given their type and context *)
37
evar_defs -> env -> ?src:loc * hole_kind -> ?filter:bool list -> types -> evar_defs * constr
38
(* the same with side-effects *)
40
evar_defs ref -> env -> ?src:loc * hole_kind -> ?filter:bool list -> types -> constr
42
(* Create a fresh evar in a context different from its definition context:
43
[new_evar_instance sign evd ty inst] creates a new evar of context
44
[sign] and type [ty], [inst] is a mapping of the evar context to
45
the context where the evar should occur. This means that the terms
46
of [inst] are typed in the occurrence context and their type (seen
47
as a telescope) is [sign] *)
48
val new_evar_instance :
49
named_context_val -> evar_defs -> types -> ?src:loc * hole_kind -> ?filter:bool list -> constr list -> evar_defs * constr
51
val make_pure_subst : evar_info -> constr array -> (identifier * constr) list
53
(***********************************************************)
54
(* Instantiate evars *)
56
(* [evar_define choose env ev c] try to instantiate [ev] with [c] (typed in [env]),
57
possibly solving related unification problems, possibly leaving open
58
some problems that cannot be solved in a unique way (except if choose is
59
true); fails if the instance is not valid for the given [ev] *)
60
val evar_define : ?choose:bool -> env -> existential -> constr -> evar_defs -> evar_defs
62
(***********************************************************)
63
(* Evars/Metas switching... *)
65
(* [evars_to_metas] generates new metavariables for each non dependent
66
existential and performs the replacement in the given constr; it also
67
returns the evar_map extended with dependent evars *)
68
val evars_to_metas : evar_map -> open_constr -> (evar_map * constr)
70
val non_instantiated : evar_map -> (evar * evar_info) list
72
(***********************************************************)
73
(* Unification utils *)
75
val is_ground_term : evar_defs -> constr -> bool
76
val is_ground_env : evar_defs -> env -> bool
78
(env -> evar_defs -> conv_pb -> constr -> constr -> evar_defs * bool)
79
-> env -> evar_defs -> existential_key -> constr array -> constr array ->
81
val solve_simple_eqn :
82
(env -> evar_defs -> conv_pb -> constr -> constr -> evar_defs * bool)
83
-> ?choose:bool -> env -> evar_defs -> conv_pb * existential * constr ->
86
(* [check_evars env initial_sigma extended_sigma c] fails if some
87
new unresolved evar remains in [c] *)
88
val check_evars : env -> evar_map -> evar_defs -> constr -> unit
90
val define_evar_as_product : evar_defs -> existential -> evar_defs * types
91
val define_evar_as_lambda : evar_defs -> existential -> evar_defs * types
92
val define_evar_as_sort : evar_defs -> existential -> evar_defs * sorts
94
val is_unification_pattern_evar : env -> existential -> constr list ->
96
val is_unification_pattern : env * int -> constr -> constr array ->
98
val solve_pattern_eqn : env -> constr list -> constr -> constr
100
val evars_of_term : constr -> Intset.t
101
val evars_of_named_context : named_context -> Intset.t
102
val evars_of_evar_info : evar_info -> Intset.t
104
(***********************************************************)
105
(* Value/Type constraints *)
107
val judge_of_new_Type : unit -> unsafe_judgment
109
type type_constraint_type = (int * int) option * constr
110
type type_constraint = type_constraint_type option
112
type val_constraint = constr option
114
val empty_tycon : type_constraint
115
val mk_tycon_type : constr -> type_constraint_type
116
val mk_abstr_tycon_type : int -> constr -> type_constraint_type
117
val mk_tycon : constr -> type_constraint
118
val mk_abstr_tycon : int -> constr -> type_constraint
119
val empty_valcon : val_constraint
120
val mk_valcon : constr -> val_constraint
123
loc -> env -> evar_defs -> type_constraint ->
124
evar_defs * (name * type_constraint * type_constraint)
126
val valcon_of_tycon : type_constraint -> val_constraint
128
val lift_abstr_tycon_type : int -> type_constraint_type -> type_constraint_type
130
val lift_tycon_type : int -> type_constraint_type -> type_constraint_type
131
val lift_tycon : int -> type_constraint -> type_constraint
133
(***********************************************************)
135
(* [whd_ise] raise [Uninstantiated_evar] if an evar remains uninstantiated; *)
136
(* *[whd_evar]* and *[nf_evar]* leave uninstantiated evar as is *)
138
val nf_evar : evar_map -> constr -> constr
139
val j_nf_evar : evar_map -> unsafe_judgment -> unsafe_judgment
141
evar_map -> unsafe_judgment list -> unsafe_judgment list
143
evar_map -> unsafe_judgment array -> unsafe_judgment array
145
evar_map -> unsafe_type_judgment -> unsafe_type_judgment
147
val nf_evar_info : evar_map -> evar_info -> evar_info
148
val nf_evars : evar_map -> evar_map
150
val nf_named_context_evar : evar_map -> named_context -> named_context
151
val nf_rel_context_evar : evar_map -> rel_context -> rel_context
152
val nf_env_evar : evar_map -> env -> env
154
(* Same for evar defs *)
155
val nf_isevar : evar_defs -> constr -> constr
156
val j_nf_isevar : evar_defs -> unsafe_judgment -> unsafe_judgment
158
evar_defs -> unsafe_judgment list -> unsafe_judgment list
160
evar_defs -> unsafe_judgment array -> unsafe_judgment array
162
evar_defs -> unsafe_type_judgment -> unsafe_type_judgment
164
val nf_evar_defs : evar_defs -> evar_defs
166
(* Replacing all evars *)
167
exception Uninstantiated_evar of existential_key
168
val whd_ise : evar_map -> constr -> constr
169
val whd_castappevar : evar_map -> constr -> constr
171
(* Replace the vars and rels that are aliases to other vars and rels by *)
172
(* their representative that is most ancient in the context *)
173
val expand_vars_in_term : env -> constr -> constr
175
(*********************************************************************)
176
(* debug pretty-printer: *)
178
val pr_tycon_type : env -> type_constraint_type -> Pp.std_ppcmds
179
val pr_tycon : env -> type_constraint -> Pp.std_ppcmds
182
(*********************************************************************)
183
(* Removing hyps in evars'context; *)
184
(* raise OccurHypInSimpleClause if the removal breaks dependencies *)
186
type clear_dependency_error =
187
| OccurHypInSimpleClause of identifier option
188
| EvarTypingBreak of existential
190
exception ClearDependencyError of identifier * clear_dependency_error
192
val clear_hyps_in_evi : evar_defs ref -> named_context_val -> types ->
193
identifier list -> named_context_val * types