如何在交互式Ocaml中获取类型信息? [英] How to get type information in interactive Ocaml?
本文介绍了如何在交互式Ocaml中获取类型信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用版本4的Ocaml.当我交互式地定义某种类型时,解释器将在此之后立即打印出该类型的字符串表示形式:
I am using Ocaml of version 4. When I define interactively some type, the interpreter prints out string representation of the type immediately after that:
# type foo = Yes | No;; <-- This is what I entered
type foo = Yes | No <-- This is what interpreter bounced
但是在输入更多定义后,有时我想再次看到该类型的文本表示形式.
But after I type more definitions, sometimes I want to see the text representation of the type again.
在Haskell中,我可以输入:t foo".
In Haskell, I could type ":t foo".
如何在Ocaml中做到这一点?
How can I do this in Ocaml?
推荐答案
在utop中,您可以使用#typeof
指令:
In utop you can use the #typeof
directive:
#typeof "list";;
type 'a list = [] | :: of 'a * 'a list
您可以将值和类型放在双引号内
You can put values and types inside double quotes:
let t = [`Hello, `World];;
#typeof "t";;
val t : ([> `Hello ] * [> `World ]) list
P.S.甚至更好的解决方案是使用merlin.
P.S. And even better solution would be to use merlin.
这篇关于如何在交互式Ocaml中获取类型信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文