0
votes

Learning OCaml is rapidly bringing me to the point of complete physical exhaustion...

In this page

https://ocaml.org/learn/tutorials/modules.html

it says

In the ocaml toplevel, the following trick allows to visualize the contents of an existing module, such as List:

# module M = List;;
module M :
  sig
    val length : 'a list -> int
    val hd : 'a list -> 'a
    val tl : 'a list -> 'a list
    val nth : 'a list -> int -> 'a
    val rev : 'a list -> 'a list
    ...

When I type the exact same thing, character-by-character, at the toplevel, the only output I get is

module M = List

I.e., a helpful echo of what I just typed (minus the ;;), which at least reassures me that the interpreter is not lost in some infinite loop.

What do I need to do to get the advertised behavior?

1
What do you mean by "the toplevel"? There are several top-level environments at this point. In the standalone OCaml interpreter (CLI ocaml command) the module M = List trick works (and has for forever). You are possibly using something else, or have things in your .ocamlinit file that affect the behavior. - Jeffrey Scofield
The one I tried was the one I get when I type ocaml at the CLI. My .ocamlinit file is empty. - kjo

1 Answers

5
votes

This trick only works for older ocaml versions ( < 4.02.X )

With the latest ocaml version you have to use '#show_module' , e.g.

#show_module List ;;