I\'m a OCaml newbie working with some pretty complex (at least for me) OCaml code I didn\'t write. It would help a lot to understand it if I could see the inferred types for
First, you must compile your file (foo.ml
) with the -annot
flag. This generates the annotation file (foo.annot
) that contains type information about all identifiers inside. You can include this as part of your makefile or build process.
Then, you need to rely on your IDE to display that information. I do this in Tuareg (the emacs mode) using Ctrl+C, Ctrl+T, which highlights the current expression and displays its type.
What works for me when reading OCaml code is to begin with the .mli
files to see what the overall structure of the project is. From there, and having an idea of what are the dependencies, you can explore from the toplevel.
Alternatively, you can ocamlc -i
the file in question for an overview of all the declared types and values, or use Tuareg mode in Emacs as replied elsewhere, if you are of that persuasion.
OcaIDE which is an O'Caml plug-in for Eclipse displays the inferred types on the fly while editing your code.
Example:
You could enter the code into the ocaml toplevel. Yeah, it's not as pretty, but it'll show the types.