在将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时,除了析因内部的注释丢失之外,其他所有功能都正常运行:
$ 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')}}
答案 0 :(得分:5)
否,这是不可能的。仔细检查一下,您可以看到the AST for the internal language that extraction targets(称为vML)(自v8.9起)没有任何注释构造函数。相关文件位于Coq存储库plugins/extraction/miniml.ml
中。