gpt4 book ai didi

ocaml - 在 OCaml utop 中使用多个模块

转载 作者:行者123 更新时间:2023-12-04 03:38:10 24 4
gpt4 key购买 nike

我最近正在阅读一个 OCaml 项目,我想将源文件放在 utop 中,以便我可以做一些实验。
假设我有两个文件 模块.ml , bmodule.ml .
bmodule.ml 将使用 中定义的函数模块.ml ,例如 模块 使用 Amodule.anyfunction() 其中 anyfunction() 在 中定义模块.ml .

我想把它们都放在 utop 中:

#directory "/directory contain amodule.ml and bmodule.ml"
#use "amodule.ml"
#use "bmodule.ml"

这不起作用,因为 模块是基于 的模块名称模块.ml 文件和 utop 不知道这些东西,我想。
那么如何在不改变文件内容的情况下将这些文件放到 utop 中呢?

最佳答案

#use a.ml执行 a.ml 中的每个语句,就像您直接在顶层键入这些语句一样。因此,您不会得到 module A已定义,因此您的其他文件不能包含 A.foo 之类的内容.如果你想要module A ,必须先字节编译a.ml,然后#load a.cmo .

关于ocaml - 在 OCaml utop 中使用多个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20579238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com