Using the tactic from Ltac2#

So far, we had to use Camltac Eval to evaluate our tactic inside a proof. Another alternative would be to declare our tactic as an Ltac2 tactic, so that existing proof scripts could use it more easily.

Registering the tactic to Ltac2#

We can create an Ltac2 tactic from a Camltac tactic by using the FFI module:

Tutorial.v#
41(* … *)
42
43Camltac Run ocaml:{{
44  Ltac2.FFI.(define "apply_search"
45    (unit @-> tac unit)
46    ApplySearch.run)
47}}.

The unit @-> tac unit specifies the type to the Ltac2 FFI from OCaml.

We must also register our tactic on the Ltac2 side to be able to call it directly by name:

Tutorial.v#
49Require Import Ltac2.Ltac2.
50
51Ltac2 @external apply_search : unit -> unit :=
52  "rocq-camltac.plugin.runtime" "apply_search".

Calling the tactic#

We can now directly call the tactic from Ltac2:


forall (A : Type) (x y z : list A), x ++ y = x ++ z -> y = z

forall (A : Type) (x y z : list A), x ++ y = x ++ z -> y = z
A: Type
x, y, z: list A

x ++ y = x ++ z -> y = z
Try this: Stdlib.Lists.List.app_inv_head
A: Type
x, y, z: list A

x ++ y = x ++ z -> y = z

Using Ltac2 notations, we can even obtain the original apply? syntax:

Ltac2 Notation "apply?" := apply_search ().


forall (A : Type) (x y z : list A), x ++ y = x ++ z -> y = z

forall (A : Type) (x y z : list A), x ++ y = x ++ z -> y = z
A: Type
x, y, z: list A

x ++ y = x ++ z -> y = z
Try this: Stdlib.Lists.List.app_inv_head
A: Type
x, y, z: list A

x ++ y = x ++ z -> y = z