Help getting started: problem opening Core in utop

I’ve just installed opam and ocaml on Debian Testing via apt, then did opam install utop, added ``eval `opam config env``` to my ~/.bashrc, and I can now start up and use utop as a calculator.

Utop tells me the versions I have are:

Welcome to utop version 2.0.1 (using OCaml version 4.02.3)

I wanted to install Core (to follow along with RWO), and did opam install core to get it. It downloaded and installed a bunch of packages, and seemed to have succeeded. If I try installing again, I get:

$ opam install core
[NOTE] Package core is already installed (current version is 113.33.03).

Now when I start utop and do “open Core.Std;;”, it tells me “Error: Unbound module Core”.

Did I install Core correctly?
Is there some other config to be done to get Core properly installed?


You have to first load the libraries you want to use. First do #require "core", and then open Core should work. (Note it is now simply open Core instead of open Core.Std.)

1 Like

Thanks, ashish. This seems to work:

#require "core";;
open Core;;

Why does “require” have the pound sign but “open” does not?


#require is a toplevel directive. There are several other useful directives. Type #help to see them all:

utop # #help;;
                              General                                                                                                                                               #help                                                                                                                                                                                 Prints a list of all available directives, with corresponding argument type                                                                                                       
  if appropriate.
  Exit the toplevel.

                              Loading code
#cd <str>
  Change the current working directory.
#directory <str>
  Add the given directory to search path for source and compiled files.
#load <str>
  Load in memory a bytecode object, produced by ocamlc.
#load_rec <str>
  As #load, but loads dependencies recursively.
#mod_use <str>
  Usage is identical to #use but #mod_use wraps the contents in a module.
#remove_directory <str>
  Remove the given directory from the search path.
#use <str>
  Read, compile and execute source phrases from the given file.

                              Environment queries
#show <ident>
  Print the signatures of components from any of the above categories.
#show_class <ident>
  Print the signature of the corresponding class.
#show_class_type <ident>
  Print the signature of the corresponding class type.
#show_exception <ident>
  Print the signature of the corresponding exception.
#show_module <ident>
  Print the signature of the corresponding module.
#show_module_type <ident>
  Print the signature of the corresponding module type.
#show_type <ident>
  Print the signature of the corresponding type constructor.
#show_val <ident>
  Print the signature of the corresponding value.

#install_printer <ident>
  Registers a printer for values of a certain type.
#print_depth <int>
  Limit the printing of values to a maximal depth of n.
#print_length <int>
  Limit the number of value nodes printed to at most n.
#remove_printer <ident>
  Remove the named function from the table of toplevel printers.

#trace <ident>
  All calls to the function named function-name will be traced.
#untrace <ident>
  Stop tracing the given function.
  Stop tracing all functions traced so far.

                              Compiler options
#labels <bool>
  Choose whether to ignore labels in function types.
#ppx <str>
  After parsing, pipe the abstract syntax tree through the preprocessor
#principal <bool>
  Make sure that all types are derived in a principal way.
  Allow arbitrary recursive types during type-checking.
#warn_error <str>
  Treat as errors the warnings enabled by the argument.
#warnings <str>
  Enable or disable warnings according to the argument.

#predicates <str>
#require <str>
#require <str>
#topfind_verbose <bool>
#typeof <str>
1 Like

Thanks! Though, #help;; doesn’t get me that display:

utop # #help;;
Unknown directive `help'.

How can I get it to display those directives?

Strange. I’m on the same version of utop as you. Not sure why it wouldn’t work.

Just to add another data point, I’m on utop 1.19.3 and #help;; gives me the same error message as it does @uvtc.