How to show the types of each declaraion of a ocaml program?

冷暖自知 提交于 2019-12-11 19:23:21

问题


I like to use ocaml in a terminal to get interactive result or type from each ocaml command, for instance:

        Objective Caml version 3.11.2

# let a = 5;;
val a : int = 5

But when there are many commands, it is normal that we put all in a file like test.ml, then compile it. At the moment, I use ocamlc -o test test.ml. But when I do test in a terminal, I could not see the types of each declaration, which is a pity.

Does anyone know how to show that? Thank you very much.


回答1:


In the toplevel you can load the entire file by, #use "filename", and this is similar to typing directly into the top-level.

For compiling, you can generate the the type information by adding the -i option to the compiler. This will print the defined names to standard out, which can be piped to a file for a quick and dirty way to generate an mli file.

For more detailed type information you can add the -annot option, which will print the type, scope, and tail-call information for every label in the file. It would have to be parsed since it isn't directly obvious from the file what is happening. There are plugins for emacs and vim, and probably eclipse, that can do this for you.

Tools to help in ocaml type annotations were discussed in another thread.



来源:https://stackoverflow.com/questions/6388803/how-to-show-the-types-of-each-declaraion-of-a-ocaml-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!