是否可以在交互式OCaml中看到已加载模块的界面?我(尝试不成功)试图寻找这种可能性,而在线文档/来源并不是我想要的.
标准技巧是为模块定义一个同义词,这会导致顶层列出接口.
$ ocaml
OCaml version 4.00.1
# #load "str.cma";;
# module S = Str;;
module S :
sig
type regexp = Str.regexp
val regexp : string -> regexp
val regexp_case_fold : string -> regexp
val quote : string -> string
val regexp_string : string -> regexp
val regexp_string_case_fold : string -> regexp
val string_match : regexp -> string -> int -> bool
. . .
val first_chars : string -> int -> string
val last_chars : string -> int -> string
end
Run Code Online (Sandbox Code Playgroud)
无论UTOP和OCaml的翻译增加了#show指令,因为一时。它完全符合您的要求,如下例所示:
? Welcome to utop version 1.19.3 (using OCaml version 4.04.0) ?
????????????????????????????????????????????????????????????????
Type #utop_help for help about using utop.
?( 15:12:33 )?< command 0 >??????????????????????????????????????{ counter: 0 }?
utop # #show List;;
module List :
sig
val length : 'a list -> int
val cons : 'a -> 'a list -> 'a list
val hd : 'a list -> 'a
...
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
end
Run Code Online (Sandbox Code Playgroud)
PS:我使用的是 4.04 版本,但我知道它也适用于 4.03。> 也许在此之前也是如此。