Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See inferred types in complex OCaml code

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 some of the values, as I can do with F# and Visual Studio by hovering over any value, e.g.:

F# showing inferred type

(screenshot borrowed from http://theburningmonk.com/2010/01/learning-f-part-1/)

I guess I could break down the code and feed it to the toplevel to get the types, but is there any other, simpler way?

like image 456
Mauricio Scheffer Avatar asked May 12 '11 16:05

Mauricio Scheffer


2 Answers

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.

like image 195
Victor Nicollet Avatar answered Oct 23 '22 03:10

Victor Nicollet


OcaIDE which is an O'Caml plug-in for Eclipse displays the inferred types on the fly while editing your code.

Example:

enter image description here

like image 44
0xFF Avatar answered Oct 23 '22 01:10

0xFF