Unbound module Base, unbound directive require

This has been asked before, but the answers there do not solve my problem:

$ ocaml
        OCaml version 4.12.0

# open Base;;
Error: Unbound module Base
# require "base";;
Error: Unbound value require
# #require "base";;
Unknown directive `require'.
#

Can anyone help?

Try doing (assuming you have installed base in your system):

# #use "topfind";;
# #require "base";;

(note the leading # before use and require).

Cheers,
Nicolas

Unfortunately it does not help.

# #use "topfind";;
Cannot find file topfind.
# #require "base";;
Unknown directive `require'.

I wonder why it does not even know “require”

BTW, my ocaml had been installed on my Mac by
brew install ocaml

In that case you will need to install findlib first. Try doing

brew install ocaml-findlib

and retrying the above.

Cheers,
Nicolas

By the way, the recommended way to install ocaml nowadays is to use opam. If you have opam installed, you can just do opam install base to install the base library and then everything should work.

You can install opam on OS X by doing brew install opam.

Cheers,
Nicolas

1 Like

Thanks. I am getting further, but …

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "base";;
No such package: base

It still does not find base …

You need to install it, it does not come with the compiler. The easiest way to install it is to use opam (see my previous message.

Cheers,
Nicolas

It still does not work …

$ opam install base
[NOTE] Package base is already installed (current version is v0.14.1).
$ ocaml
        OCaml version 4.12.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "base";;
No such package: base

It may be that you now have two different ocaml installations: that of opam and that of brew. To make sure you are using the one from opam, type

eval $(opam env)

and try again.

Cheers,
Nicolas

2 Likes

Nope …

$ eval $(opam env)
$ ocaml
        OCaml version 4.12.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

- : unit = ()
# #require "base";;
No such package: base

Thanks a lot for your help, Nicolas, I really appreciate it. Meanwhile, I think I’d better try my luck with another language. There are many functional languages after all

What’s the output of ocamlfind printconf ?

Cheers,
Nicolas

What’s the output of:

$ opam list

Is base listed in the output? If so, then it is definitely installed in the current opam switch. If not, you need to install it with: opam install base.

Finally, it is recommended to use the enhanced OCaml REPL, utop:

$ opam install utop
$ utop
utop # #require "base";;

utop automatically loads findlib for you and provides other conveniences as well, like autocomplete, and history.

$ ocamlfind printconf
Effective configuration:
Configuration file:
    /usr/local/etc/findlib.conf
Search path:
    /usr/local/lib/ocaml
Packages will be installed in/removed from:
    /usr/local/lib/ocaml
META files will be installed in/removed from:
    the corresponding package directories
The standard library is assumed to reside in:
    /usr/local/lib/ocaml
The ld.conf file can be found here:
    /usr/local/lib/ocaml/ld.conf
$ opam list
# Packages matching: installed
# Name            # Installed # Synopsis
base              v0.14.1     Full standard library replacement for OCaml
base-bigarray     base
base-threads      base
base-unix         base
csexp             1.5.1       Parsing and printing of S-expressions in Canonical
dune              2.9.0       Fast, portable, and opinionated build system
dune-configurator 2.9.0       Helper library for gathering system configuration
ocaml             4.12.0      The OCaml compiler (virtual package)
ocaml-config      2           OCaml Switch Configuration
ocaml-system      4.12.0      The OCaml compiler (system version, from outside o
result            1.5         Compatibility Result module
sexplib0          v0.14.0     Library containing the definition of S-expressions

Finally, this works! Thanks!

1 Like

Hi, @gefei ! Would you mind sharing what learning material or documentation you were using to get oriented and set up with OCaml? It sounds like we’ll want to update or deprecate it (as appropriate), so we can save future users from the pain of going down tough set up paths.

2 Likes

Hi @shonfeder I was learning OCaml by the book “Real world ocaml” https://dev.realworldocaml.org/, and I had problem with the very first line in the first example which reads open Base;;

2 Likes

Thanks! I looks like RWO advises installing from opam. Is it possible you’d consulted different material initially for the installation, that advised installing from homebrew?