Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ocaml

utop

In utop, when opening a library (via ~require ...) or when opening a module (via open Module_name), is there a way to get the content of the library or module? utop offers this by completion tabs, but I would like to see all the functions at once.

like image 766
Pierre G. Avatar asked Nov 19 '15 05:11

Pierre G.


People also ask

What does :: mean in OCaml?

Regarding the :: symbol - as already mentioned, it is used to create lists from a single element and a list ( 1::[2;3] creates a list [1;2;3] ). It is however worth noting that the symbol can be used in two different ways and it is also interpreted in two different ways by the compiler.

What is a list in OCaml?

An OCaml list is a sequence of values all of which have the same type. They are implemented as singly-linked lists. These lists enjoy a first-class status in the language: there is special support for easily creating and working with lists. That's a characteristic that OCaml shares with many other functional languages.

What is OCaml top level?

In short, the toplevel is OCaml's Read-Eval-Print-Loop (repl) allowing interative use of the OCaml system. You can consider the toplevel an alternative to compiling OCaml into an executable.


2 Answers

In utop you can use the #show command. For example

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
like image 116
Stas Avatar answered Sep 30 '22 19:09

Stas


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 big signatures.

like image 21
camlspotter Avatar answered Sep 30 '22 18:09

camlspotter