| 1 |
|
| 2 |
Rocq Extraction |
| 3 |
=============== |
| 4 |
|
| 5 |
|
| 6 |
What is it ? |
| 7 |
------------ |
| 8 |
|
| 9 |
The extraction is a mechanism that produces functional code |
| 10 |
(Ocaml/Haskell/Scheme) out of any Rocq terms (either programs or |
| 11 |
proofs). |
| 12 |
|
| 13 |
Who did it ? |
| 14 |
------------ |
| 15 |
|
| 16 |
The current implementation (from version 7.0 up to now) has been done |
| 17 |
by P. Letouzey during his PhD, helped by J.C. Filliâtre and supervised |
| 18 |
by C. Paulin. |
| 19 |
|
| 20 |
An earlier implementation (versions 6.x) was due to B. Werner and |
| 21 |
C. Paulin. |
| 22 |
|
| 23 |
|
| 24 |
Where can we find more information ? |
| 25 |
------------------------------------ |
| 26 |
|
| 27 |
- Rocq Reference Manual includes a full chapter about extraction |
| 28 |
- P. Letouzey's PhD thesis [3] forms a complete document about |
| 29 |
both theory and implementation and test-cases of Rocq extraction |
| 30 |
- A more recent article [4] proposes a short overview of extraction |
| 31 |
- earlier documents [1] [2] may also be useful. |
| 32 |
|
| 33 |
|
| 34 |
Why a complete re-implementation ? |
| 35 |
---------------------------------- |
| 36 |
|
| 37 |
Extraction code has been completely rewritten since version V6.3. |
| 38 |
|
| 39 |
1) Principles |
| 40 |
|
| 41 |
The main goal of the new extraction is to handle any Rocq term, even |
| 42 |
those upon sort Type, and to produce code that always compiles. |
| 43 |
Thus it will never answer something like "Not an ML type", but rather |
| 44 |
a dummy term like the ML unit. |
| 45 |
|
| 46 |
Translation between Rocq and ML is based upon the following principles: |
| 47 |
|
| 48 |
- Terms of sort Prop don't have any computational meaning, so they are |
| 49 |
merged into one ML term "__". This part is done according to P. Letouzey's |
| 50 |
works [1] and [2]. |
| 51 |
|
| 52 |
This dummy constant "__" used to be implemented by the unit (), but |
| 53 |
we recently found that this constant might be applied in some cases. |
| 54 |
So "__" is now in Ocaml a fixpoint that forgets its arguments: |
| 55 |
|
| 56 |
let __ = let rec f _ = Obj.repr f in Obj.repr f |
| 57 |
|
| 58 |
|
| 59 |
- Terms that are type schemes (i.e. something of type ( : )( : )...s with |
| 60 |
s a sort ) don't have any ML counterpart at the term level, since they |
| 61 |
are types transformers. In fact they do not have any computational |
| 62 |
meaning either. So we also merge them into that dummy term "__". |
| 63 |
|
| 64 |
- A Rocq term gives a ML term or a ML type depending of its type: |
| 65 |
type schemes will (try to) give ML types, and all other terms give ML terms. |
| 66 |
|
| 67 |
And the rest of the translation is (almost) straightforward: an inductive |
| 68 |
gives an inductive, etc... |
| 69 |
|
| 70 |
This gives ML code that have no special reason to typecheck, due |
| 71 |
to the incompatibilities between Rocq and ML typing systems. In fact |
| 72 |
most of the time everything goes right. |
| 73 |
|
| 74 |
We now verify during extraction that the produced code is typecheckable, |
| 75 |
and if it is not we insert unsafe type casting at critical points in the |
| 76 |
code, with either "Obj.magic" in Ocaml or "unsafeCoerce" in Haskell. |
| 77 |
|
| 78 |
|
| 79 |
2) Differences with previous extraction (V6.3 and before) |
| 80 |
|
| 81 |
2.a) The pros |
| 82 |
|
| 83 |
The ability to extract every Rocq term, as explain in the previous |
| 84 |
paragraph. |
| 85 |
|
| 86 |
The ability to extract from a file an ML module (cf Extraction Library in the |
| 87 |
documentation) |
| 88 |
|
| 89 |
You can have a taste of extraction directly at the toplevel by |
| 90 |
using the "Extraction <ident>" or the "Recursive Extraction <ident>". |
| 91 |
This toplevel extraction was already there in V6.3, but was printing |
| 92 |
Fw terms. It now prints in the language of your choice: |
| 93 |
Ocaml, Haskell or Scheme. |
| 94 |
|
| 95 |
The optimization done on extracted code has been ported between |
| 96 |
V6.3 and V7 and enhanced, and in particular the mechanism of automatic |
| 97 |
expansion. |
| 98 |
|
| 99 |
2.b) The cons |
| 100 |
|
| 101 |
The presence of some parasite "__" as dummy arguments |
| 102 |
in functions. This denotes the rests of a proof part. The previous |
| 103 |
extraction was able to remove them totally. The current implementation |
| 104 |
removes a good deal of them, but not all. |
| 105 |
|
| 106 |
This problem is due to extraction upon Type. |
| 107 |
For example, let's take this pathological term: |
| 108 |
(if b then Set else Prop) : Type |
| 109 |
The only way to know if this is an Set (to keep) or a Prop (to remove) |
| 110 |
is to compute the boolean b, and we do not want to do that during |
| 111 |
extraction. |
| 112 |
|
| 113 |
There is no more "ML import" feature. You can compensate by using |
| 114 |
Axioms, and then "Extract Constant ..." |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
[1]: |
| 121 |
Exécution de termes de preuves: une nouvelle méthode d'extraction |
| 122 |
pour le Calcul des Constructions Inductives, Pierre Letouzey, |
| 123 |
DEA thesis, 2000, |
| 124 |
http://www.pps.jussieu.fr/~letouzey/download/rapport_dea.ps.gz |
| 125 |
|
| 126 |
[2]: |
| 127 |
A New Extraction for Coq, Pierre Letouzey, |
| 128 |
Types 2002 Post-Workshop Proceedings. |
| 129 |
http://www.pps.jussieu.fr/~letouzey/download/extraction2002.ps.gz |
| 130 |
|
| 131 |
[3]: |
| 132 |
Programmation fonctionnelle certifiée: l'extraction de programmes |
| 133 |
dans l'assistant Coq. Pierre Letouzey, PhD thesis, 2004. |
| 134 |
http://www.pps.jussieu.fr/~letouzey/download/these_letouzey.ps.gz |
| 135 |
http://www.pps.jussieu.fr/~letouzey/download/these_letouzey_English.ps.gz |
| 136 |
|
| 137 |
[4]: |
| 138 |
Coq Extraction, An overview. Pierre Letouzey. CiE2008. |
| 139 |
http://www.pps.jussieu.fr/~letouzey/download/letouzey_extr_cie08.pdf |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|