未绑定的模块Base



当我尝试在文件中编写这个程序,然后用dune编译和执行时,我正在遵循OCaml的本教程。

open Base
open Stdio
let rec read_and_accumulate accum =
let line = In_channel.input_line In_channel.stdin in
match line with
| None -> accum
| Some x -> read_and_accumulate (accum +. Float.of_string x)
let () =
printf "Total: %Fn" (read_and_accumulate 0.)

然而,我得到了错误"unbound module Base"。在网上查找时,我找到了将#require “base”;;添加到.ocminit文件的解决方案,这允许我在utop中使用该模块,但它仍然无法使用dune运行文件。如何从文件运行此程序?

根据您提供的少量信息,我只能猜测您没有编写正确的沙丘文件。它应该是这样的::

(executable
(name read_and_acc)
(libraries base))

相关内容

最新更新