在保留注释的同时将Coq提取到Haskell

问题描述 投票:7回答:1

无论如何在将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')}}
haskell comments coq
1个回答
5
投票

不,这是不可能的。要仔细检查,您可以看到名为MiniML的the AST for the internal language that extraction targets(从v8.9开始)没有任何用于注释的构造函数。相关文件位于Coq存储库plugins/extraction/miniml.ml中。

© www.soinside.com 2019 - 2024. All rights reserved.