首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OCaml字符串和Coq字符串(从Coq提取到OCaml)

OCaml字符串和Coq字符串(从Coq提取到OCaml)
EN

Stack Overflow用户
提问于 2014-09-02 03:03:30
回答 1查看 571关注 0票数 2

我使用了从Coq到OCaml的提取,其中有ZNpositive类型。

我不需要在int of OCaml中提取它。

那么提取后的类型是:

代码语言:javascript
复制
type positive =
| Coq_xI of positive
| Coq_xO of positive
| Coq_xH

type coq_N =
| N0
| Npos of positive

type coq_Z =
| Z0
| Zpos of positive
| Zneg of positive

我在OCaml中有一个程序,其中一些函数使用OCaml类型的string

在我的OCaml程序中,我需要编写一些转换类型的函数:string -> coq_Nstring -> coq_Zstring -> positive

我尝试用Coq编写函数,然后使用提取来获得OCaml类型,但是Coq string与OCaml string不同。

例如:

代码语言:javascript
复制
open Ascii
open BinNums
open Datatypes

type string =
| EmptyString
| String of ascii * string

let string_of_coqN (s: string): coq_N =
  match s with
    | EmptyString -> N0
    | String (a, _) -> (coq_N_of_ascii a);;

其中coq_N_of_ascii是从coq函数N_of_ascii中提取的。

例如,当我应用函数string_of_coqN时:

代码语言:javascript
复制
let test (x: string) = string_of_N x;;

我接到的投诉是

代码语言:javascript
复制
Error: This expression has type string but an expression was expected of type
         String0.string

您能帮我找到一种编写转换函数的方法吗:string -> coq_Nstring -> coq_Zstring -> positive

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-02 12:15:40

对于字符串,最简单的方法可能是在提取文件中导入标准库模块ExtrOcamlString,这将导致Coq在OCaml中将它们提取为char list。然后可以使用自定义代码在char list和本机string之间进行转换。例如,查看CompCert发行版、函数camlstring_of_coqstringcoqstring_of_camlstring中的文件camlstring_of_coqstring

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25615238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档