Debian Codegraph @

theories/Ltac2/Constr.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 Require Import Ltac2.Init.
12 Require Ltac2.Ind Ltac2.Array.
13
14 Ltac2 @ external type : constr -> constr := "rocq-runtime.plugins.ltac2" "constr_type".
15 (** Return the type of a term *)
16
17 Ltac2 @ external equal : constr -> constr -> bool := "rocq-runtime.plugins.ltac2" "constr_equal".
18 (** Strict syntactic equality: only up to α-conversion and evar expansion *)
19
20 Module Binder.
21
22 Ltac2 Type relevance_var.
23 Ltac2 Type relevance := [ Relevant | Irrelevant | RelevanceVar (relevance_var) ].
24 (** This type will eventually be removed in favour of Relevance.t as an abstract type. *)
25
26 Ltac2 @ external make : ident option -> constr -> binder := "rocq-runtime.plugins.ltac2" "constr_binder_make".
27 (** Create a binder given the name and the type of the bound variable.
28 Fails if the type is not a type in the current goal. *)
29
30 Ltac2 @ external unsafe_make : ident option -> relevance -> constr -> binder := "rocq-runtime.plugins.ltac2" "constr_binder_unsafe_make".
31 (** Create a binder given the name and the type and relevance of the bound variable. *)
32
33 Ltac2 @ external name : binder -> ident option := "rocq-runtime.plugins.ltac2" "constr_binder_name".
34 (** Retrieve the name of a binder. *)
35
36 Ltac2 @ external type : binder -> constr := "rocq-runtime.plugins.ltac2" "constr_binder_type".
37 (** Retrieve the type of a binder. *)
38
39 Ltac2 @ external relevance : binder -> relevance := "rocq-runtime.plugins.ltac2" "constr_binder_relevance".
40 (** Retrieve the relevance of a binder. *)
41
42 End Binder.
43
44 Module Relevance.
45
46 (** Type of proof relevance: relevant, irrelevant or a variable
47 (either locally rigid variable from sort polymorphism, or
48 unification variable from elaboration). *)
49 Ltac2 Type t := Binder.relevance.
50
51 (** Test equality of relevances in the current proof state
52 (the proof state matters for unification sort variables,
53 which may be instantiated). *)
54 Ltac2 @external equal : t -> t -> bool
55 := "rocq-runtime.plugins.ltac2" "constr_relevance_equal".
56
57 Ltac2 @external relevant : t
58 := "rocq-runtime.plugins.ltac2" "constr_relevance_relevant".
59
60 Ltac2 @external irrelevant : t
61 := "rocq-runtime.plugins.ltac2" "constr_relevance_irrelevant".
62
63 End Relevance.
64
65 Module Unsafe.
66
67 (** Low-level access to kernel terms. Use with care! *)
68
69 Ltac2 Type case.
70 (** A value of [case] is data carried by a pattern match expression that
71 contains a reference to the inductive type being matched on. Given an
72 inductive type, one can use the [case] function below to construct pattern
73 match expressions on that type, or given a pattern match expression one can
74 use the [Case.inductive] function to get the inductive type associated to
75 the pattern match. *)
76
77 Ltac2 Type case_invert
78 (** A piece of metadata attached to a pattern match expression which
79 tells Rocq which reduction rule to use for the pattern match *)
80 := [
81 | NoInvert
82 (** The normal reduction rule: reduce the pattern match exactly when the
83 scrutinee is a constructor. *)
84 | CaseInvert (constr array)
85 (** The special reduction rule for eliminating out of an [SProp] into a
86 non-[SProp]. Normally such elimination is only legal when the [SProp] has no
87 constructors, in which case the match is irreducible. If the [SProp] was
88 defined with the [Definitional UIP] flag on, and the [SProp] has one
89 constructor which takes no non-parameter arguments, then the match is
90 reducible if the indices for the scrutinee are unifiable with the indices
91 for the unique constructor. See the [Definitional UIP] section of the
92 [SProp] documentation in the refman for more information. *)
93 ].
94
95 Ltac2 Type kind := [
96 | Rel (int)
97 (** de Bruijn local variable, bound by a surrounding binder such as [forall], [fun], etc.
98 No [Rel] is bound in a goal's context: the goal context is all [Var]s. *)
99 | Var (ident)
100 (** Named variable (section variables and proof context variables are treated identically) *)
101 | Meta (meta)
102 (** An older, legacy implementation of unification variables. This is probably
103 dead code. *)
104 | Evar (evar, constr array)
105 (** Existential variable (unification variable). In [Evar evar array], [evar] is the existential variable
106 itself and [array] is the local variable instance, i.e. values for each of the variables in the evar's context.
107 For an evar [x : T1, y : T2 |- ?e : Te], [?e@{x:=e1; y:=e2}] gives array [[|e2; e1|]].
108 See also flag [Printing Existential Instances] in the refman. *)
109 | Sort (sort)
110 (** A sort such as Prop, SProp, Type@{u}, a polymorphic sort Type@{s|u}, etc. (cf. refman Core language > Sorts) *)
111 | Cast (constr, cast, constr)
112 (** [Cast t1 k t2] corresponds to the syntactic term [(t1 : t2)], i.e.,
113 the programmer declares that [t1] is of type [t2]. [k] is a flag telling
114 the kernel what strategy should be used to validate this assertion,
115 e.g., VM or native evaluation. *)
116 | Prod (binder, constr)
117 (** Concrete syntax ["forall A:B,C"] is represented as [Prod (A:B) C].
118 [A] is bound as a [Rel] in [C]. *)
119 | Lambda (binder, constr)
120 (** Concrete syntax ["fun A:B => C"] is represented as [Lambda (A:B) C].
121 [A] is bound as a [Rel] in [C]. *)
122 | LetIn (binder, constr, constr)
123 (** Concrete syntax ["let A:C := B in D"] is represented as
124 [LetIn (A:C) B D]. [A] is bound as a [Rel] in [D]. *)
125 | App (constr, constr array)
126 (** Application is n-ary. Concrete syntax ["(F P1 P2 ... Pn)"] is represented as [App (F, [|P1; P2; ...; Pn|])]. *)
127 | Constant (constant, instance)
128 (** [Constant c ui] is the constant [c] @ universe instance [ui]. *)
129 | Ind (inductive, instance)
130 (** A name of an inductive or coinductive type. [Ind ind ui] is [ind@[ui]] *)
131 | Constructor (constructor, instance)
132 (** A constructor of an inductive type. [Constructor c ui] is [c@[ui]]. *)
133 | Case (case, (constr * Relevance.t), case_invert, constr, constr array)
134 (** [Case case (fun u1 u2 ... un v => rettype, _) ci scrut
135 [|(fun x1 x2 => t1);(fun y1 y2 y3 => t2));...|]]
136 corresponds to
137 [match scrut in I u1 u2 ... as v return rettype with
138 | c0 _ _ x1 x2 => t1
139 | c1 _ _ y1 y2 y3 => t2
140 | (...)
141 end].
142 [ci] is of interest when [scrut] inhabits an [SProp], see comments on the type
143 [case_invert] above. [case] contains a reference to the inductive type of the scrutinee.*)
144 | Fix (int array, int, binder array, constr array)
145 (** [fix fun0 (b00 : B00) (b01 : B01) (...) {struct b0_k0} : C0 := t0 with
146 fun1 (b10 : B10) (b11 : B11) (...) {struct b1_k1} : C1 := t1 with
147 (...)
148 for funi]
149 is represented as
150 [Fix [|k0;k1;...|] i [|
151 fun0 : forall (b00 : B00) (b01 : B01) (...), C0;
152 fun1 : forall (b10 : B10) (b11 : B11) (...), C1;
153 (...)
154 |] [|
155 fun b00 b01 (...) => t0;
156 fun b00 b01 (...) => t1;
157 (...)
158 |]] *)
159 | CoFix (int, binder array, constr array)
160 | Proj (projection, Relevance.t, constr)
161 (** [Proj p r c] is [c.(p)]. The relevance is the relevance of the whole term. *)
162 | Uint63 (uint63)
163 | Float (float)
164 | String (pstring)
165 | Array (instance, constr array, constr, constr)
166 (** [Array u vals def t] is the primitive array literal [[|vals | def : t|]@{u}]. *)
167 ].
168
169 Ltac2 @ external kind : constr -> kind := "rocq-runtime.plugins.ltac2" "constr_kind".
170
171 Ltac2 rec kind_nocast c :=
172 match kind c with
173 | Cast c _ _ => kind_nocast c
174 | k => k
175 end.
176
177 Ltac2 @ external make : kind -> constr := "rocq-runtime.plugins.ltac2" "constr_make".
178
179 Ltac2 @ external check : constr -> constr result := "rocq-runtime.plugins.ltac2" "constr_check".
180 (** Checks that a constr generated by unsafe means is indeed safe in the
181 current environment, and returns it, or the error otherwise. Panics if
182 not focused. *)
183
184 Ltac2 @ external liftn : int -> int -> constr -> constr := "rocq-runtime.plugins.ltac2" "constr_liftn".
185 (** [liftn n k c] lifts by [n] indices greater than or equal to [k] in [c]
186 Note that with respect to substitution calculi's terminology, [n]
187 is the _shift_ and [k] is the _lift_. *)
188
189 Ltac2 @ external substnl : constr list -> int -> constr -> constr := "rocq-runtime.plugins.ltac2" "constr_substnl".
190 (** [substnl [r₁;...;rₙ] k c] substitutes in parallel [Rel(k+1); ...; Rel(k+n)] with
191 [r₁;...;rₙ] in [c]. *)
192
193 Ltac2 @ external closenl : ident list -> int -> constr -> constr := "rocq-runtime.plugins.ltac2" "constr_closenl".
194 (** [closenl [x₁;...;xₙ] k c] abstracts over variables [x₁;...;xₙ] and replaces them with
195 [Rel(k); ...; Rel(k+n-1)] in [c]. If two names are identical, the one of least index is kept. *)
196
197 Ltac2 @ external closedn : int -> constr -> bool := "rocq-runtime.plugins.ltac2" "constr_closedn".
198 (** [closedn n c] is true iff [c] is a closed term under [n] binders *)
199
200 Ltac2 is_closed (c : constr) : bool := closedn 0 c.
201 (** [is_closed c] is true iff [c] is a closed term (contains no [Rel]s) *)
202
203 Ltac2 @ external noccur_between : int -> int -> constr -> bool := "rocq-runtime.plugins.ltac2" "constr_noccur_between".
204 (** [noccur_between n m c] returns true iff [Rel p] does not occur in term [c]
205 for [n <= p < n+m] *)
206
207 #[deprecated(since="9.0", note="occur_between currently behaves as noccur_between.
208 Use noccur_between instead if you want [true] for variables which do not occur in the term
209 and its negation if you want [false].")]
210 Ltac2 occur_between := noccur_between.
211
212 Ltac2 noccurn (n : int) (c : constr) : bool := noccur_between n 1 c.
213 (** [noccurn n c] returns true iff [Rel n] does not occur in term [c] *)
214
215 #[deprecated(since="9.0", note="occurn currently behaves as noccurn.
216 Use noccurn instead if you want [true] for variables which do not occur in the term
217 and its negation if you want [false].")]
218 Ltac2 occurn (n : int) (c : constr) : bool := noccur_between n 1 c.
219
220 Ltac2 @ external case : inductive -> case := "rocq-runtime.plugins.ltac2" "constr_case".
221 (** Generate the case information for a given inductive type. *)
222
223 Ltac2 constructor (ind : inductive) (i : int) : constructor :=
224 Ind.get_constructor (Ind.data ind) i.
225 (** Generate the i-th constructor for a given inductive type. Indexing starts
226 at 0. Panics if there is no such constructor. *)
227
228 Module Case.
229 Ltac2 @ external equal : case -> case -> bool := "rocq-runtime.plugins.ltac2" "constr_case_equal".
230 (** Checks equality of the inductive components of the
231 case info. When comparing the inductives, those obtained through
232 module aliases or Include are not considered equal by this
233 function. *)
234
235 Ltac2 @ external inductive : case -> inductive := "rocq-runtime.plugins.ltac2" "case_to_inductive".
236 (** Get the inductive type being matched on in a pattern match expression. *)
237 End Case.
238
239 (** Open recursion combinators *)
240
241 Local Ltac2 iter_invert (f : constr -> unit) (ci : case_invert) : unit :=
242 match ci with
243 | NoInvert => ()
244 | CaseInvert indices => Array.iter f indices
245 end.
246
247 (** [iter f c] iterates [f] on the immediate subterms of [c]; it is
248 not recursive and the order with which subterms are processed is
249 not specified *)
250 Ltac2 iter (f : constr -> unit) (c : constr) : unit :=
251 match kind c with
252 | Rel _ | Meta _ | Var _ | Sort _ | Constant _ _ | Ind _ _
253 | Constructor _ _ | Uint63 _ | Float _ | String _ => ()
254 | Cast c _ t => f c; f t
255 | Prod b c => f (Binder.type b); f c
256 | Lambda b c => f (Binder.type b); f c
257 | LetIn b t c => f (Binder.type b); f t; f c
258 | App c l => f c; Array.iter f l
259 | Evar _ l => Array.iter f l
260 | Case _ x iv y bl =>
261 match x with (x,_) => f x end;
262 iter_invert f iv;
263 f y;
264 Array.iter f bl
265 | Proj _p _ c => f c
266 | Fix _ _ tl bl =>
267 Array.iter (fun b => f (Binder.type b)) tl;
268 Array.iter f bl
269 | CoFix _ tl bl =>
270 Array.iter (fun b => f (Binder.type b)) tl;
271 Array.iter f bl
272 | Array _u t def ty =>
273 f ty; Array.iter f t; f def
274 end.
275
276 (** [iter_with_binders g f n c] iterates [f n] on the immediate
277 subterms of [c]; it carries an extra data [n] (typically a lift
278 index) which is processed by [g] (which typically add 1 to [n]) at
279 each binder traversal; it is not recursive and the order with which
280 subterms are processed is not specified *)
281 Ltac2 iter_with_binders (g : 'a -> binder -> 'a) (f : 'a -> constr -> unit) (n : 'a) (c : constr) : unit :=
282 match kind c with
283 | Rel _ | Meta _ | Var _ | Sort _ | Constant _ _ | Ind _ _
284 | Constructor _ _ | Uint63 _ | Float _ | String _ => ()
285 | Cast c _ t => f n c; f n t
286 | Prod b c => f n (Binder.type b); f (g n b) c
287 | Lambda b c => f n (Binder.type b); f (g n b) c
288 | LetIn b t c => f n (Binder.type b); f n t; f (g n b) c
289 | App c l => f n c; Array.iter (f n) l
290 | Evar _ l => Array.iter (f n) l
291 | Case _ x iv y bl =>
292 match x with (x,_) => f n x end;
293 iter_invert (f n) iv;
294 f n y;
295 Array.iter (f n) bl
296 | Proj _p _ c => f n c
297 | Fix _ _ tl bl =>
298 Array.iter (fun b => f n (Binder.type b)) tl;
299 let n := Array.fold_left g n tl in
300 Array.iter (f n) bl
301 | CoFix _ tl bl =>
302 Array.iter (fun b => f n (Binder.type b)) tl;
303 let n := Array.fold_left g n tl in
304 Array.iter (f n) bl
305 | Array _u t def ty =>
306 f n ty;
307 Array.iter (f n) t;
308 f n def
309 end.
310
311 Local Ltac2 binder_map (f : constr -> constr) (b : binder) : binder :=
312 Binder.unsafe_make (Binder.name b) (Binder.relevance b) (f (Binder.type b)).
313
314 Local Ltac2 map_invert (f : constr -> constr) (iv : case_invert) : case_invert :=
315 match iv with
316 | NoInvert => NoInvert
317 | CaseInvert indices => CaseInvert (Array.map f indices)
318 end.
319
320 (** [map f c] maps [f] on the immediate subterms of [c]; it is
321 not recursive and the order with which subterms are processed is
322 not specified *)
323 Ltac2 map (f : constr -> constr) (c : constr) : constr :=
324 match kind c with
325 | Rel _ | Meta _ | Var _ | Sort _ | Constant _ _ | Ind _ _
326 | Constructor _ _ | Uint63 _ | Float _ | String _ => c
327 | Cast c k t =>
328 let c := f c
329 with t := f t in
330 make (Cast c k t)
331 | Prod b c =>
332 let b := binder_map f b
333 with c := f c in
334 make (Prod b c)
335 | Lambda b c =>
336 let b := binder_map f b
337 with c := f c in
338 make (Lambda b c)
339 | LetIn b t c =>
340 let b := binder_map f b
341 with t := f t
342 with c := f c in
343 make (LetIn b t c)
344 | App c l =>
345 let c := f c
346 with l := Array.map f l in
347 make (App c l)
348 | Evar e l =>
349 let l := Array.map f l in
350 make (Evar e l)
351 | Case info x iv y bl =>
352 let x := match x with (x,x') => (f x, x') end
353 with iv := map_invert f iv
354 with y := f y
355 with bl := Array.map f bl in
356 make (Case info x iv y bl)
357 | Proj p r c =>
358 let c := f c in
359 make (Proj p r c)
360 | Fix structs which tl bl =>
361 let tl := Array.map (binder_map f) tl
362 with bl := Array.map f bl in
363 make (Fix structs which tl bl)
364 | CoFix which tl bl =>
365 let tl := Array.map (binder_map f) tl
366 with bl := Array.map f bl in
367 make (CoFix which tl bl)
368 | Array u t def ty =>
369 let ty := f ty
370 with t := Array.map f t
371 with def := f def in
372 make (Array u t def ty)
373 end.
374
375 (** [map_with_binders g f n c] maps [f n] on the immediate subterms of [c];
376 it carries an extra data [n] (typically a lift index) which is processed by [g]
377 (which typically add 1 to [n]) at each binder traversal;
378 it is not recursive and the order with which subterms are processed is not specified. *)
379 Ltac2 map_with_binders (lift : 'a -> binder -> 'a) (f : 'a -> constr -> constr) (n : 'a) (c : constr) : constr :=
380 match kind c with
381 | Rel _ | Meta _ | Var _ | Sort _ | Constant _ _ | Ind _ _
382 | Constructor _ _ | Uint63 _ | Float _ | String _ => c
383 | Cast c k t =>
384 let c := f n c
385 with t := f n t in
386 make (Cast c k t)
387 | Prod b c =>
388 let b := binder_map (f n) b
389 with c := f (lift n b) c in
390 make (Prod b c)
391 | Lambda b c =>
392 let b := binder_map (f n) b
393 with c := f (lift n b) c in
394 make (Lambda b c)
395 | LetIn b t c =>
396 let b := binder_map (f n) b
397 with t := f n t
398 with c := f (lift n b) c in
399 make (LetIn b t c)
400 | App c l =>
401 let c := f n c
402 with l := Array.map (f n) l in
403 make (App c l)
404 | Evar e l =>
405 let l := Array.map (f n) l in
406 make (Evar e l)
407 | Case info x iv y bl =>
408 let x := match x with (x,x') => (f n x, x') end
409 with iv := map_invert (f n) iv
410 with y := f n y
411 with bl := Array.map (f n) bl in
412 make (Case info x iv y bl)
413 | Proj p r c =>
414 let c := f n c in
415 make (Proj p r c)
416 | Fix structs which tl bl =>
417 let tl := Array.map (binder_map (f n)) tl in
418 let n_bl := Array.fold_left lift n tl in
419 let bl := Array.map (f n_bl) bl in
420 make (Fix structs which tl bl)
421 | CoFix which tl bl =>
422 let tl := Array.map (binder_map (f n)) tl in
423 let n_bl := Array.fold_left lift n tl in
424 let bl := Array.map (f n_bl) bl in
425 make (CoFix which tl bl)
426 | Array u t def ty =>
427 let ty := f n ty
428 with t := Array.map (f n) t
429 with def := f n def in
430 make (Array u t def ty)
431 end.
432
433 End Unsafe.
434
435 Module Cast.
436
437 Ltac2 @ external default : cast := "rocq-runtime.plugins.ltac2" "constr_cast_default".
438 Ltac2 @ external vm : cast := "rocq-runtime.plugins.ltac2" "constr_cast_vm".
439 Ltac2 @ external native : cast := "rocq-runtime.plugins.ltac2" "constr_cast_native".
440
441 Ltac2 @ external equal : cast -> cast -> bool := "rocq-runtime.plugins.ltac2" "constr_cast_equal".
442
443 End Cast.
444
445 Ltac2 @ external in_context : ident -> constr -> (unit -> unit) -> constr := "rocq-runtime.plugins.ltac2" "constr_in_context".
446 (** On a focused goal [Γ ⊢ A], [in_context id c tac] evaluates [tac] in a
447 focused goal [Γ, id : c ⊢ ?X] and returns [fun (id : c) => t] where [t] is
448 the proof built by the tactic. *)
449
450 Module Pretype.
451 Module Flags.
452 Ltac2 Type t.
453
454 Ltac2 @ external constr_flags : t := "rocq-runtime.plugins.ltac2" "constr_flags".
455 (** The flags used by constr:(). *)
456
457 Ltac2 @external set_use_coercions : bool -> t -> t
458 := "rocq-runtime.plugins.ltac2" "pretype_flags_set_use_coercions".
459 (** Use coercions during pretyping. [true] in [constr_flags]. *)
460
461 Ltac2 @external set_use_typeclasses : bool -> t -> t
462 := "rocq-runtime.plugins.ltac2" "pretype_flags_set_use_typeclasses".
463 (** Run typeclass inference at the end of pretyping and when
464 needed according to flag "Typeclass Resolution For Conversion".
465 [true] in [constr_flags]. *)
466
467 Ltac2 @external set_allow_evars : bool -> t -> t
468 := "rocq-runtime.plugins.ltac2" "pretype_flags_set_allow_evars".
469 (** Allow pretyping to produce new unresolved evars.
470 [false] in [constr_flags]. *)
471
472 Ltac2 @external set_nf_evars : bool -> t -> t
473 := "rocq-runtime.plugins.ltac2" "pretype_flags_set_nf_evars".
474 (** Evar-normalize the result of pretyping. This should not impact
475 anything other than performance.
476 [true] in [constr_flags]. *)
477
478 Ltac2 Abbreviation open_constr_flags_with_tc :=
479 set_nf_evars false (set_allow_evars true constr_flags).
480
481 Local Ltac2 open_constr_flags_with_tc_kn () := open_constr_flags_with_tc.
482 (** Code generation uses this as using the notation is not convenient. *)
483
484 Ltac2 Abbreviation open_constr_flags_no_tc :=
485 set_use_typeclasses false open_constr_flags_with_tc.
486 (** The flags used by open_constr:() and its alias [']. *)
487
488 #[deprecated(since="8.20", note="use open_constr_flags_with_tc (or open_constr_flags_no_tc as desired)")]
489 Ltac2 Abbreviation open_constr_flags := open_constr_flags_with_tc.
490 End Flags.
491
492 Ltac2 Type expected_type.
493
494 Ltac2 @ external expected_istype : expected_type
495 := "rocq-runtime.plugins.ltac2" "expected_istype".
496
497 Ltac2 @ external expected_oftype : constr -> expected_type
498 := "rocq-runtime.plugins.ltac2" "expected_oftype".
499
500 Ltac2 @ external expected_without_type_constraint : expected_type
501 := "rocq-runtime.plugins.ltac2" "expected_without_type_constraint".
502
503 Ltac2 @ external pretype : Flags.t -> expected_type -> preterm -> constr
504 := "rocq-runtime.plugins.ltac2" "constr_pretype".
505 (** Pretype the provided preterm. Assumes the goal to be focussed. *)
506 End Pretype.
507
508 Ltac2 pretype (c : preterm) : constr :=
509 Pretype.pretype Pretype.Flags.constr_flags Pretype.expected_without_type_constraint c.
510 (** Pretype the provided preterm. Assumes the goal to be focussed. *)
511
512 Ltac2 decompose_app_list (c : constr) :=
513 match Unsafe.kind c with
514 | Unsafe.App f cl => (f, Array.to_list cl)
515 | _ => (c,[])
516 end.
517
518 Ltac2 decompose_app (c : constr) :=
519 match Unsafe.kind c with
520 | Unsafe.App f cl => (f, cl)
521 | _ => (c,[| |])
522 end.
523
524 Ltac2 is_evar(c: constr) :=
525 match Unsafe.kind c with
526 | Unsafe.Evar _ _ => true
527 | _ => false
528 end.
529
530 Ltac2 @ external has_evar : constr -> bool := "rocq-runtime.plugins.ltac2" "constr_has_evar".
531
532 Ltac2 is_var(c: constr) :=
533 match Unsafe.kind c with
534 | Unsafe.Var _ => true
535 | _ => false
536 end.
537
538 Ltac2 is_fix(c: constr) :=
539 match Unsafe.kind c with
540 | Unsafe.Fix _ _ _ _ => true
541 | _ => false
542 end.
543
544 Ltac2 is_cofix(c: constr) :=
545 match Unsafe.kind c with
546 | Unsafe.CoFix _ _ _ => true
547 | _ => false
548 end.
549
550 Ltac2 is_ind(c: constr) :=
551 match Unsafe.kind c with
552 | Unsafe.Ind _ _ => true
553 | _ => false
554 end.
555
556 Ltac2 is_constructor(c: constr) :=
557 match Unsafe.kind c with
558 | Unsafe.Constructor _ _ => true
559 | _ => false
560 end.
561
562 Ltac2 is_proj(c: constr) :=
563 match Unsafe.kind c with
564 | Unsafe.Proj _ _ _ => true
565 | _ => false
566 end.
567
568 Ltac2 is_const(c: constr) :=
569 match Unsafe.kind c with
570 | Unsafe.Constant _ _ => true
571 | _ => false
572 end.
573
574 Ltac2 is_float(c: constr) :=
575 match Unsafe.kind c with
576 | Unsafe.Float _ => true
577 | _ => false
578 end.
579
580 Ltac2 is_uint63(c: constr) :=
581 match Unsafe.kind c with
582 | Unsafe.Uint63 _ => true
583 | _ => false
584 end.
585
586 Ltac2 is_string(c: constr) :=
587 match Unsafe.kind c with
588 | Unsafe.String _ => true
589 | _ => false
590 end.
591
592 Ltac2 is_array(c: constr) :=
593 match Unsafe.kind c with
594 | Unsafe.Array _ _ _ _ => true
595 | _ => false
596 end.
597
598 Ltac2 is_sort(c: constr) :=
599 match Unsafe.kind c with
600 | Unsafe.Sort _ => true
601 | _ => false
602 end.