查看复杂的OCaml代码中的推断类型 [英] See inferred types in complex OCaml code

查看:69
本文介绍了查看复杂的OCaml代码中的推断类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OCaml新手,正在处理一些我没有编写的非常复杂的OCaml代码(至少对我而言).如果我可以看到某些值的推断类型,这将对理解很有帮助,就像我可以通过悬停在任何值上来使用F#和Visual Studio一样,例如:

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.:

(屏幕快照来自 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?

推荐答案

首先,必须使用-annot标志编译文件(foo.ml).这将生成注释文件(foo.annot),该文件包含有关内部所有标识符的类型信息.您可以将其作为makefile或构建过程的一部分.

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.

然后,您需要依靠IDE来显示该信息.我使用 Ctrl + C Ctrl + T 在Tuareg(emacs模式)中执行此操作当前表达式并显示其类型.

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.

这篇关于查看复杂的OCaml代码中的推断类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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