简体   繁体   中英

unbound module Base

I am following this tutorial for OCaml when I try to write this program in a file and then compile and execute with dune.

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.)

However I get the error 'unbound module Base'. Looking online I found the solution of adding #require “base”;; to the.ocamlinit file and that allows me to use the module in utop but it still won't work with running a file using dune. How can I run this program from a file?

With the small amount of informations you're giving I can only guess that you didn't write a proper dune file. It should look like this::

(executable
 (name read_and_acc)
 (libraries base))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM