| 1 |
Require Import Ltac2.Ltac2. |
| 2 |
|
| 3 |
Import Constr.Unsafe. |
| 4 |
|
| 5 |
(* manual Ltac1.lambda wrapping *) |
| 6 |
Ltac add1 := |
| 7 |
ltac2val:(Ltac1.lambda (fun y => |
| 8 |
let y := Option.get (Ltac1.to_constr y) in |
| 9 |
let y := make (App constr:(S) [|y|]) in |
| 10 |
Ltac1.of_constr y)). |
| 11 |
|
| 12 |
(* automatic Ltac1.lambda wrapping |
| 13 |
also check that it's done in the right order *) |
| 14 |
Ltac add1' := |
| 15 |
ltac2val:(y z |- |
| 16 |
let y := Option.get (Ltac1.to_constr y) in |
| 17 |
let y := make (App constr:(S) [|y|]) in |
| 18 |
Ltac1.of_constr y). |
| 19 |
|
| 20 |
Set Default Proof Mode "Classic". |
| 21 |
|
| 22 |
Goal True. |
| 23 |
let z := constr:(0) in |
| 24 |
let v := add1 z in |
| 25 |
constr_eq v 1. |
| 26 |
|
| 27 |
let a := constr:(0) in |
| 28 |
let v := add1' a 2 in |
| 29 |
constr_eq v 1. |
| 30 |
|
| 31 |
(* currying works *) |
| 32 |
let a := constr:(0) in |
| 33 |
let v := add1' a in |
| 34 |
let v' := v 2 in |
| 35 |
constr_eq v' 1. |
| 36 |
|
| 37 |
(* check order of arguments *) |
| 38 |
Fail let a := constr:(0) in |
| 39 |
let v := add1' 2 a in |
| 40 |
constr_eq v 1. |
| 41 |
|
| 42 |
(* printer doesn't anomaly *) |
| 43 |
let v := add1' in |
| 44 |
idtac v. |
| 45 |
|
| 46 |
Abort. |
| 47 |
|
| 48 |
(* With ltac2:(x) this would succeed without warning |
| 49 |
"this expression should have type unit but has type constr" |
| 50 |
because ltac2:(x) only checks that x has type unifiable with unit. |
| 51 |
It's not a big problem as the constr gets discarded by ltac2:() |
| 52 |
so we just get an incomplete warning (maybe fixed in the future). |
| 53 |
|
| 54 |
With ltac2val such a weak check would produce runtime anomalies. |
| 55 |
*) |
| 56 |
Fail Ltac2 bad x := |
| 57 |
let c1 := constr:(ltac:(ltac2val:(x))) in |
| 58 |
let c2 := constr:($x) in |
| 59 |
(). |