标签: utop

utop 支持哪些顶级指令?

我找不到关于我可以在 utop 中使用哪些顶级指令的任何文档。我所能找到的只是这个默认 ocaml 顶层支持的指令列表,但该列表对于 utop 似乎并不完整,并且缺少诸如 之类的东西#typeof,我知道它在 utop 中有效。

ocaml utop

4
推荐指数
1
解决办法
480
查看次数

utop中的自动完成

我很抱歉这个新问题,但我刚开始使用OCaml而且我找不到如何使用utop自动完成功能.

当我开始在utop中输入内容时,我会在shell的底部看到一个选项列表.如果只有一个有效选项,按TAB将自动完成我正在写的内容.但如果有多个有效的选择,并且我发现了我想要的那个,我还没有找到一种方法来选择它(除了继续写作).

例如(假设我已导入Core.Std)我输入

Float.of
Run Code Online (Sandbox Code Playgroud)

第一个建议是Float.of_float,第二个建议是Float.of_int.如何选择第二个?

ocaml autocomplete utop

3
推荐指数
1
解决办法
1290
查看次数

OCaml 的 utop:导入外部模块

我有兴趣将Angstrom(一个解析组合器库)引入到我的项目中。

我将 Angstrom 安装到我的系统中,opam如下所示:

$> opam install angstrom
Run Code Online (Sandbox Code Playgroud)

我还使用以下命令成功地参考相关模块编译了该项目ocamlfind

$> ocamlbuild -use-ocamlfind -pkgs 'angstrom' project.byte
Run Code Online (Sandbox Code Playgroud)

令人惊讶的是,我在将 Angstrom 导入 repl 时遇到问题utop。像这样的命令#open Angstrom指示绑定到模块名称的值。我已经搜索了从 repl 导入模块的文档,但没有找到我正在寻找的结果。

引用外部模块的最佳方式是什么utop

ocaml utop

3
推荐指数
1
解决办法
1350
查看次数

在 utop 中加载具有依赖项的模块

我有两个模块A.mlB.ml如下所示:

A.ml:

type t = int
let from_int (i : int) : t = i
Run Code Online (Sandbox Code Playgroud)

B.ml:

open A
let my_t : t = from_int 0
Run Code Online (Sandbox Code Playgroud)

我可以通过调用来编译它们ocamlc A.ml B.ml,但是我不知道如何加载它们utop以便my_t交互使用。使用:

  • utop -init B.ml产量Error: Reference to undefined global 'A'
  • utop后面跟着#use "A.ml";;and#use "B.ml";;会导致同样的错误
  • 删除open AfromB.ml使这双重#use工作,但ocamlc A.ml B.ml现在失败BError: Unbound type constructor t

ocaml utop

3
推荐指数
1
解决办法
3053
查看次数

dune utop 一些可执行文件

对于单个文件可执行文件,如何加载它dune utop

lib准确地说,在目录中有库和相应文件的项目上dune,我可以启动dune utop libopen Lib.MyModule这将加载文件MyModule.ml

对于没有子目录且根目录下有以下文件的项目来说,相当于一个dune文件

(executable
  (name auth)
  (libraries ezjsonm cryptokit))
Run Code Online (Sandbox Code Playgroud)

和一个文件auth.ml

let hi = "value"
Run Code Online (Sandbox Code Playgroud)

我想从该文件中加载值dune utop

ocaml utop ocaml-dune

3
推荐指数
1
解决办法
773
查看次数

OCaml 中的“int/2”类型是什么

当我在交互环境(OCamlutop)中执行以下命令时,所有“int”类型的表达式都变成了“int/2”类型。这种行为可以复制如下。

# 3;;
- : int = 3

# type int;;
type int

# type a;;
type a

# 3;;
- : int/2 = 3
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么会这样?谢谢!

2020 年 3 月 2 日编辑:

我发现如果我执行以下操作,“int/2”将不会出现。谁能解释一下这里发生了什么?

# 3;;
- : int = 3

# type int;;
type int

# 3;;
- : int = 3
Run Code Online (Sandbox Code Playgroud)

更新:以上情况使用了OCaml 4.08.1 版

ocaml utop

2
推荐指数
1
解决办法
110
查看次数

为什么我的 OCaml“=”运算符仅适用于 int?

我使用 vscode,带有“OCaml 和 Reason IDE”的扩展

这是我在 utop 中的结果:

utop # 1. = 1. ;;    
Line 1, characters 0-2:
Error: This expression has type float but an expression was expected of type
             int
Run Code Online (Sandbox Code Playgroud)

对于字符串也同样如此:

utop # "Me" = "Me";;
Line 1, characters 0-4:
Error: This expression has type string but an expression was expected of type
         int
Run Code Online (Sandbox Code Playgroud)

除 int 之外的任何内容都相同:

utop # 2 = 2 ;;
- : bool = true
Run Code Online (Sandbox Code Playgroud)

">" "<" 也有同样的症状。我不知道到底发生了什么。谁能帮我吗 ?多谢!

ocaml utop

2
推荐指数
1
解决办法
685
查看次数

@@ deriving sexp在utop上不起作用

我在utop中运行以下代码:

# type u = { a: int; b: float } [@@deriving sexp];;
Run Code Online (Sandbox Code Playgroud)

但是不会生成s表达式转换器的预期声明。

我安装了Core 0.11.0和utop版本2.1.0。

Ocaml的版本是4.06.1。

谢谢。

ocaml utop

1
推荐指数
1
解决办法
180
查看次数

Alt + Left 和 Alt + Right 允许我在 Utop 中的自动完成之间切换,但选项卡将返回到第一个选择

在 OCaml 的 utop 中,我可以使用 alt+left 或 alt+right 在自动完成部分中移动,但是当我单击选项卡自动完成时,将使用第一个选择。我该怎么办?

search ocaml autocomplete utop

1
推荐指数
1
解决办法
160
查看次数

为什么这里不调用标记雄鹿函数?

我试图理解 OCamlFormat模块和语义标签的以下行为。

我的代码:

let prepare_ppf ppf =
  let original_stag_functions = Format.pp_get_formatter_stag_functions ppf () in
  let original_mark_tags_state = Format.pp_get_mark_tags ppf () in
  Format.pp_set_mark_tags ppf true;
  Format.pp_set_print_tags ppf false;
  Format.pp_set_formatter_stag_functions ppf {
    mark_open_stag = (fun stag ->
          print_endline "MARK-OPEN";
          match stag with
          | Format.String_tag s -> Printf.sprintf "<open:%s>" s
          | _ -> "<UNKNOWN>"
        );
    mark_close_stag = (fun stag ->
          print_endline "MARK-CLOSE";
          match stag with
          | Format.String_tag s -> Printf.sprintf "</close:%s>" s
          | _ -> "</UNKNOWN>"
        );
    print_open_stag = (fun _ …
Run Code Online (Sandbox Code Playgroud)

ocaml utop

1
推荐指数
1
解决办法
66
查看次数

标签 统计

ocaml ×10

utop ×10

autocomplete ×2

ocaml-dune ×1

search ×1