You can find utop suitable for this. This is an extended version of the standard OCaml toplevel, but with:
- more reasonable defaults for interactive use (with shortcuts enabled)
- automatic evaluation of some top-level mods, such as Lwt or Async I / O (therefore, input to int Deferred.t or int Lwt.t will return int at the top level)
- interactive history and completion of the module, as well as everything that the editor likes.
There are two ways to find the type of something. For the value, simply enter the expression at the top level:
$ utop
This works for values, but not for type definitions. utop (1.7+) also has a #typeof directive that can print this for you.
$ utop
(the latter shows that the reference type ref is just syntactic sugar for a field with one contents field changed).
Another common trick to quickly reset a module definition is its alias for the new module.
$ utop
You can quickly install utop through opam install utop . We recommend this in Real World OCaml as the preferred interactive editor for beginners rather than vanilla OCaml toplevel.
source share