How can utop know and not know a module at the same time?

As shown in the code below :


What is going on here ?

I think I asked this or a similar question here some time ago, but I can’t find it.

This can happen if the toplevel can find the .cmi file for the module, but the relevant .cmo/.cma has not been linked.


$ mkdir subdir

$ echo "let x = 1" > subdir/ 

$ ocamlc -c subdir/

$ find .

$ ocaml -I subdir
# #show Foo;;
module Foo : sig val x : int end
# Foo.x;;
Error: Reference to undefined global `Foo'

$ ocaml -I subdir subdir/foo.cmo
# Foo.x;;
- : int = 1

Summary: -I subdir makes the .cmi files of subdir/ visible to the type-checker. subdir/foo.cmo links the implementation of Foo into the program (generally: linking into the executable produced by ocamlc; here we link to make it available to the toplevel).

Got it, thanks. Out of curiosity, is this nice sequence of alterning command-line commands and ocaml-toplevel commands something you rearranged out of separate parts, or is it a toplevel feature I’m unaware of?

This is a log of my interactions with a terminal, with some useless bits (the toplevel header banner) edited out. No magic here, sorry about that :slight_smile:

1 Like