See inferred types in complex OCaml code

后端 未结 4 878
孤独总比滥情好
孤独总比滥情好 2021-01-02 09:42

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

相关标签:
4条回答
  • 2021-01-02 10:04

    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.

    0 讨论(0)
  • 2021-01-02 10:08

    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.

    0 讨论(0)
  • 2021-01-02 10:10

    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

    0 讨论(0)
  • 2021-01-02 10:30

    You could enter the code into the ocaml toplevel. Yeah, it's not as pretty, but it'll show the types.

    0 讨论(0)
提交回复
热议问题