unbound module Base

Viewed 46

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?

1 Answers

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