首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jane street Ocaml中需要一个模块

如何在jane street Ocaml中需要一个模块
EN

Stack Overflow用户
提问于 2018-10-23 12:03:56
回答 1查看 172关注 0票数 1

我正在使用http://dev.realworldocaml.org/records.html,但在使用require时遇到了问题

代码语言:javascript
复制
#require "re.posix";;

(* open Base ;;
open Core ;; *)

(* type <record-name> =
  {
    <field>: <type>;
    <field>: <type>;
  } *)

  type service_info =
    {
      service_name : string ;
      port : int ;
      protocol : string ;
    }
;;

(* #require "re.postix";; *)

let service_info_of_string line =
  let matches =
    Re.exec (Re.Posix.compile_pat "([a-zA-Z]+)[\t]+([0-9]+)/([a-zA-Z]+)") line
  in
  {
    service_name = Re.get matches 1;
    port = Int.of_string (Re.get matches 2);
    protocol = Re.get matches 3;
  }
;;

print_endline "foobar"

这是我调用dune build的输出

代码语言:javascript
复制
dune build hello_world.exe 
         ppx hello_world.pp.ml (exit 1)
(cd _build/default && .ppx/jbuild/ppx_jane/ppx.exe -o hello_world.pp.ml --impl hello_world.ml --dump-ast)
File "hello_world.ml", line 385, characters 0-1:
Error: Syntax error

下面是jbuild

代码语言:javascript
复制
(executable
 ((name hello_world)
 (libraries (core))
 (preprocess (pps (ppx_jane)))))

我发现"#use "topfind“如果我用ocamlc编译就行了,但还没能用沙丘编译。

Tips appreciated.thanks

EN

回答 1

Stack Overflow用户

发布于 2018-10-24 17:20:23

以下修复将使您的示例正常工作:

代码语言:javascript
复制
open Core ;; (* in particular, it makes Int visible *)


type service_info =
    {
      service_name : string ;
      port : int ;
      protocol : string ;
    }
;;

(* #require "re.postix";; *)

let service_info_of_string line =
  let matches =
    Re.exec (Re.Posix.compile_pat "([a-zA-Z]+)[\t]+([0-9]+)/([a-zA-Z]+)") line
  in
  {
    service_name = Re.get matches 1;
    port = Int.of_string (Re.get matches 2);
    protocol = Re.get matches 3;
  }
;;

print_endline "foobar"

jbuild

代码语言:javascript
复制
(executable
 ((name hello_world)
 (libraries (core re))
 (preprocess (pps (ppx_jane)))))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52941010

复制
相关文章

相似问题

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