将 Coq 提取到 Haskell,同时保留注释
Extracting Coq to Haskell while keeping comments
在将 Coq 提取到 Haskell 时是否可以保留注释?
理想情况下,我希望机器生成的 Haskell 文件不被人类修改,因此提取评论的动机很明确。但是,我找不到如何去做,我想知道这是否完全可能(?)。这是一个示例 Coq 文件:
(*************)
(* factorial *)
(*************)
Fixpoint factorial (n : nat) : nat :=
match n with
| 0 => 1
| 1 => 1 (* this case is redundant *)
| S n' => (mult n (factorial n'))
end.
Compute (factorial 7).
(********************************)
(* Extraction Language: Haskell *)
(********************************)
Extraction Language Haskell.
(***************************)
(* Extract to Haskell file *)
(***************************)
Extraction "/home/oren/Downloads/RPRP/output.hs" factorial.
当我将它提取到 Haskell 时,除了 factorial 中的注释丢失之外,一切正常:
$ coqc ./input.v > /dev/null
$ cat ./output.hs
module Output where
import qualified Prelude
data Nat =
O
| S Nat
add :: Nat -> Nat -> Nat
add n m =
case n of {
O -> m;
S p -> S (add p m)}
mul :: Nat -> Nat -> Nat
mul n m =
case n of {
O -> O;
S p -> add m (mul p m)}
factorial :: Nat -> Nat
factorial n =
case n of {
O -> S O;
S n' ->
case n' of {
O -> S O;
S _ -> mul n (factorial n')}}
不,这不可能。仔细检查,您可以看到 the AST for the internal language that extraction targets, called MiniML, doesn't (as of v8.9) have any constructors for comments. The relevant file is in the Coq repository, plugins/extraction/miniml.ml
.
在将 Coq 提取到 Haskell 时是否可以保留注释? 理想情况下,我希望机器生成的 Haskell 文件不被人类修改,因此提取评论的动机很明确。但是,我找不到如何去做,我想知道这是否完全可能(?)。这是一个示例 Coq 文件:
(*************)
(* factorial *)
(*************)
Fixpoint factorial (n : nat) : nat :=
match n with
| 0 => 1
| 1 => 1 (* this case is redundant *)
| S n' => (mult n (factorial n'))
end.
Compute (factorial 7).
(********************************)
(* Extraction Language: Haskell *)
(********************************)
Extraction Language Haskell.
(***************************)
(* Extract to Haskell file *)
(***************************)
Extraction "/home/oren/Downloads/RPRP/output.hs" factorial.
当我将它提取到 Haskell 时,除了 factorial 中的注释丢失之外,一切正常:
$ coqc ./input.v > /dev/null
$ cat ./output.hs
module Output where
import qualified Prelude
data Nat =
O
| S Nat
add :: Nat -> Nat -> Nat
add n m =
case n of {
O -> m;
S p -> S (add p m)}
mul :: Nat -> Nat -> Nat
mul n m =
case n of {
O -> O;
S p -> add m (mul p m)}
factorial :: Nat -> Nat
factorial n =
case n of {
O -> S O;
S n' ->
case n' of {
O -> S O;
S _ -> mul n (factorial n')}}
不,这不可能。仔细检查,您可以看到 the AST for the internal language that extraction targets, called MiniML, doesn't (as of v8.9) have any constructors for comments. The relevant file is in the Coq repository, plugins/extraction/miniml.ml
.