2

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?

Chris
  • 26,361
  • 5
  • 21
  • 42
Kronos
  • 126
  • 8
  • Did you add the `libraries` stanza in your dune file to tell dune to use base? https://dune.readthedocs.io/en/stable/dune-files.html#jbuild-version – Lhooq Sep 09 '22 at 13:19

1 Answers1

1

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))
Lhooq
  • 4,281
  • 1
  • 18
  • 37