当我试图将这个程序写进一个文件中,然后用沙丘编译并执行时,我正在跟踪本教程用于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: %F\n" (read_and_accumulate 0.)然而,我得到了错误‘未绑定模块库’。在线查看时,我找到了将#require “base”;;添加到.ocamlinit文件的解决方案,这允许我在utop中使用模块,但它仍然无法使用沙丘运行文件。如何从文件中运行此程序?
发布于 2022-09-09 13:20:30
由于你提供的信息不多,我只能猜测你没有写一个合适的沙丘文件。它应该是这样的:
(executable
(name read_and_acc)
(libraries base))https://stackoverflow.com/questions/73661504
复制相似问题