| 1 |
|
| 2 |
(** Examples of extraction with manually-declared implicit arguments *) |
| 3 |
|
| 4 |
(** NB: we should someday check the produced code instead of |
| 5 |
extracting and just compiling. *) |
| 6 |
|
| 7 |
Require Corelib.extraction.Extraction. |
| 8 |
|
| 9 |
(** Bug #4243, part 1 *) |
| 10 |
|
| 11 |
Inductive dnat : nat -> Type := |
| 12 |
| d0 : dnat 0 |
| 13 |
| ds : forall n m, n = m -> dnat n -> dnat (S n). |
| 14 |
|
| 15 |
Extraction Implicit ds [m]. |
| 16 |
|
| 17 |
Lemma dnat_nat: forall n, dnat n -> nat. |
| 18 |
Proof. |
| 19 |
intros n d. |
| 20 |
induction d as [| n m Heq d IHn]. |
| 21 |
exact 0. exact (S IHn). |
| 22 |
Defined. |
| 23 |
|
| 24 |
Recursive Extraction dnat_nat. |
| 25 |
Extraction TestCompile dnat_nat. |
| 26 |
|
| 27 |
Extraction Implicit dnat_nat [n]. |
| 28 |
Recursive Extraction dnat_nat. |
| 29 |
Extraction TestCompile dnat_nat. |
| 30 |
|
| 31 |
(** Same, with a Fixpoint *) |
| 32 |
|
| 33 |
Fixpoint dnat_nat' n (d:dnat n) := |
| 34 |
match d with |
| 35 |
| d0 => 0 |
| 36 |
| ds n m _ d => S (dnat_nat' n d) |
| 37 |
end. |
| 38 |
|
| 39 |
Recursive Extraction dnat_nat'. |
| 40 |
Extraction TestCompile dnat_nat'. |
| 41 |
|
| 42 |
Extraction Implicit dnat_nat' [n]. |
| 43 |
Recursive Extraction dnat_nat'. |
| 44 |
Extraction TestCompile dnat_nat'. |
| 45 |
|
| 46 |
(** Bug #4243, part 2 *) |
| 47 |
|
| 48 |
Inductive enat: nat -> Type := |
| 49 |
e0: enat 0 |
| 50 |
| es: forall n, enat n -> enat (S n). |
| 51 |
|
| 52 |
Lemma enat_nat: forall n, enat n -> nat. |
| 53 |
Proof. |
| 54 |
intros n e. |
| 55 |
induction e as [| n e IHe]. |
| 56 |
exact (O). |
| 57 |
exact (S IHe). |
| 58 |
Defined. |
| 59 |
|
| 60 |
Extraction Implicit es [n]. |
| 61 |
Extraction Implicit enat_nat [n]. |
| 62 |
Recursive Extraction enat_nat. |
| 63 |
Extraction TestCompile enat_nat. |
| 64 |
|
| 65 |
(** Same, with a Fixpoint *) |
| 66 |
|
| 67 |
Fixpoint enat_nat' n (e:enat n) : nat := |
| 68 |
match e with |
| 69 |
| e0 => 0 |
| 70 |
| es n e => S (enat_nat' n e) |
| 71 |
end. |
| 72 |
|
| 73 |
Extraction Implicit enat_nat' [n]. |
| 74 |
Recursive Extraction enat_nat'. |
| 75 |
Extraction TestCompile enat_nat'. |
| 76 |
|
| 77 |
(** Bug #4228 *) |
| 78 |
|
| 79 |
Module Food. |
| 80 |
Inductive Course := |
| 81 |
| main: nat -> Course |
| 82 |
| dessert: nat -> Course. |
| 83 |
|
| 84 |
Inductive Meal : Course -> Type := |
| 85 |
| one_course : forall n:nat, Meal (main n) |
| 86 |
| two_course : forall n m, Meal (main n) -> Meal (dessert m). |
| 87 |
Extraction Implicit two_course [n]. |
| 88 |
End Food. |
| 89 |
|
| 90 |
Recursive Extraction Food.Meal. |
| 91 |
Extraction TestCompile Food.Meal. |