Ocaml: utop, is there a way to list all the functions of a module?

In utop, when opening a library (via ~ require ...) or when opening a module (via open Module_name), is there a way to get the contents of a library or module? utop offers this on completion tabs, but I would like to see all the features right away.

+5
source share
3 answers

In utop you can use the #show command. for instance

 utop # #show Stack;; module Stack : sig type 'at exception Empty val create : unit -> 'at val push : 'a -> 'at -> unit val pop : 'at -> 'a val top : 'at -> 'a val clear : 'at -> unit val copy : 'at -> 'at val is_empty : 'at -> bool val length : 'at -> int val iter : ('a -> unit) -> 'at -> unit end 
+5
source

Not necessarily in utop, you can use the following:

 # module type S = module type of Module_of_your_interest;; module type S = sig ... ... end 

Warning: some modules have really large signatures.

+7
source

If you are interested in the function names available in the library, you can write:

 #module S = Library_name;; 

eg:

 #module M = String;; 

The output will be:

module M: ​​sig outer length: string β†’ int = "% string_length" external get: string β†’ int β†’ char = "% string_safe_get" external set: string β†’ int β†’ char β†’ unit = "% string_safe_set" external create: int β†’ string = "caml_create_string" val make: int β†’ char β†’ string val copy: string β†’ string val sub: string β†’ int β†’ int β†’ string val fill: string β†’ int β†’ int β†’ char β†’ unit val blit: string β†’ int β†’ string β†’ int β†’ int β†’ unit val concat: string β†’ string list β†’ string val iter: (char β†’ unit) β†’ string β†’ unit val iteri: (int β†’ char β†’ unit) β†’ string β†’ unit val map: (char β†’ char) β†’ string β†’ string val trim: string β†’ string val escaped: string β†’ string val index: string β†’ char β†’ int val rindex: string β†’ char β†’ int val index_from: string β†’ int β†’ char β†’ int val rindex_from: string β†’ int β†’ char β†’ int val contains: string β†’ char β†’ bool val contains_from: string β†’ int β†’ char β†’ bool val rcontains_from: string β†’ int β†’ char β†’ bool val uppercase: string β†’ string val lower string: string β†’ string val capitalize: string β†’ string val uncapitalize: string β†’ string type t = string val: t β†’ t β†’ int external unsafe_get: string β†’ int β†’ char = "% string_unsafe_get" external unsafe_set: string β†’ int β†’ char β†’ unit = "% string_unsafe_set" external unsafe_blit: string β†’ int β†’ string -> int -> int -> unit = "caml_blit_string" "noalloc" external unsafe_fill: string -> int -> int -> char -> unit = "caml_fill_string" "noalloc" end

After that, you can even use M as an alias for String. eg:

 # M.concat " " ["one"; "two"; "three"];; 
0
source

Source: https://habr.com/ru/post/1236289/


All Articles