ocaml:utop,有没有办法列出模块的所有功能?

Pie*_* G. 6 ocaml utop

在utop中,当打开库(通过~requires ......)或打开模块时(通过打开Module_name),有没有办法获取库或模块的内容?utop通过完成选项卡提供此功能,但我希望立即看到所有功能.

cam*_*ter 7

不一定在utop中,您可以使用以下内容:

# module type S = module type of Module_of_your_interest;;
module type S =
  sig
    ...
    ...
  end
Run Code Online (Sandbox Code Playgroud)

警告:某些模块有很大的签名.


Sta*_*tas 6

utop您可以使用该#show命令.例如

utop # #show Stack;;
module Stack :
  sig
    type 'a t
    exception Empty
    val create : unit -> 'a t
    val push : 'a -> 'a t -> unit
    val pop : 'a t -> 'a
    val top : 'a t -> 'a
    val clear : 'a t -> unit
    val copy : 'a t -> 'a t
    val is_empty : 'a t -> bool
    val length : 'a t -> int
    val iter : ('a -> unit) -> 'a t -> unit
  end
Run Code Online (Sandbox Code Playgroud)

  • 为了完整起见:在 ocaml 顶层,这将是“#show_module Stack;;” (2认同)