Skip to content

Commit b700610

Browse files
committed
API: coq.ltac.fresh-id
1 parent 8f75bcb commit b700610

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- New `tc-priority`, contains the priority of an instance and if the priority
1111
has been given by the user or computed by `coq`
1212
- Change `tc-instance`, now the type is `gref -> tc-priority -> tc-instance` i.e. the priority is not an integer anymore
13+
- New `coq.ltac.fresh-id` to generate fresh names in the proof context
1314

1415
### Apps
1516
- New `tc` app providing an implementation of a type class solver written in elpi.

coq-builtin.elpi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,9 @@ external pred coq.ltac.call-ltac1 i:any, i:goal, o:list sealed-goal.
15721572
%
15731573
external pred coq.ltac.id-free? i:id, i:goal.
15741574

1575+
% [coq.ltac.fresh-id Default Ty FreshID] TODO
1576+
external pred coq.ltac.fresh-id i:id, i:term, o:id.
1577+
15751578
% -- Coq's options system --------------------------------------------
15761579

15771580
% Coq option value

src/coq_elpi_builtins.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3789,6 +3789,20 @@ an elpi tactic.|})))),
37893789
else raise No_clause)),
37903790
DocAbove);
37913791

3792+
MLCode(Pred("coq.ltac.fresh-id",
3793+
In(B.unspec id, "Default",
3794+
CIn(B.unspecC term, "Ty",
3795+
Out(id,"FreshID",
3796+
Read(proof_context, "TODO")))),
3797+
(fun id ty _ ~depth proof_context _ _ ->
3798+
let id = match id with Unspec -> "x" | Given x -> x in
3799+
let id =
3800+
match ty with
3801+
| Unspec -> Namegen.next_ident_away (Names.Id.of_string_soft id) proof_context.names
3802+
| Given ty -> Namegen.next_name_away_with_default_using_types id Name.Anonymous proof_context.names ty in
3803+
!: (Id.to_string id))),
3804+
DocAbove);
3805+
37923806
LPDoc "-- Coq's options system --------------------------------------------";
37933807

37943808
MLData goption;

tests/test_tactic.v

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,29 @@ Goal forall n, n + 1 = 1.
389389
trivial.
390390
match goal with |- S m + 1 = 1 => idtac end.
391391
Abort.
392+
393+
394+
395+
Elpi Tactic fresh1.
396+
Elpi Accumulate lp:{{
397+
solve (goal _ _ {{ forall _ : lp:Ty, _ }} _ _ as G) GL :-
398+
coq.ltac.fresh-id "x" Ty ID,
399+
coq.id->name ID N,
400+
refine (fun N _ _) G GL.
401+
}}.
402+
Elpi Typecheck.
403+
Goal forall x z y, x = 1 + y + z.
404+
intros x x0.
405+
elpi fresh1.
406+
Check x1.
407+
Abort.
408+
409+
Implicit Type (w : nat).
410+
411+
Goal forall x z y, x = 1 + y + z.
412+
intros ??.
413+
elpi fresh1.
414+
Check w.
415+
Abort.
416+
417+

0 commit comments

Comments
 (0)