如何显示ocaml程序的每个声明的类型? [英] How to show the types of each declaraion of a ocaml program?

查看:80
本文介绍了如何显示ocaml程序的每个声明的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在终端中使用 ocaml 来从每个 ocaml 命令中获取交互式结果或类型,例如:

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

但是当命令很多的时候,我们把所有的都放在一个像test.ml这样的文件里,然后编译它是正常的.目前,我使用 ocamlc -o test test.ml.但是当我在终端中做test时,却看不到每个声明的类型,很遗憾.

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.

推荐答案

在顶层,您可以通过 #use "filename" 加载整个文件,这类似于直接在顶级.

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

对于编译,您可以通过向编译器添加-i 选项来生成类型信息.这会将定义的名称打印到标准输出,它可以通过管道传输到文件中,以快速而肮脏的方式生成 mli 文件.

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.

有关更详细的类型信息,您可以添加 -annot 选项,该选项将打印文件中每个标签的类型、范围和尾调用信息.它必须被解析,因为从文件中不能直接看出发生了什么.有适用于 emacs 和 vim 的插件,可能还有 eclipse,可以为您做到这一点.

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.

另一个线程.

这篇关于如何显示ocaml程序的每个声明的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆