Off to a bad start

Hello everyone,

I am just starting to learn ocaml through the book Real World Ocaml
I already brew installed opam and opam installed base

But when i use utop

# open Base;;     
Error: Unbound module Base

I checked using opam list -a and base module is there.

Can someone enlighten me?

you need to run

#require “base”;;

before opening it.

As for Real World OCaml, you might also check the Setting up and using utop section in the install page.

3 Likes

Just to share with other troubled beginners

Create a file at home directory ~/.ocamlinit

#require "base";;
open Base;;

It doesn’t help that the book begins by saying code examples will be based on Base but installation instructions is to install Core

Note, that this will work only in utop, to make it work in vanilla OCaml toplevel (aka ocaml) or in emacs built-in toplevel, you also need to add before everything else

#use "topfind";;

And make sure that ocamlfind is installed, e.g., by issuing the following command in your terminal (if you’re using opam)

opam install ocamlfind
1 Like

Truth be told I would be wary of adding open Base to .ocamlinit. This is likely to get you confused in case you decide to copypaste some code from the Internet in the future since it won’t work for mysterious reasons (mostly due to Base redefining = and a whole lot of modules).

4 Likes

You probably, do not have your ocaml files directly in your home directory.

You can put an .ocamlinit file in any folder and utop ocaml ocaml-top will pick it up.

1 Like