Please: I would like to examine a module's signature; is there a function to do this? Just typing the name of the module doesn't work:
# List ;;
Error: Unbound constructor List
In fact I want to do this for modules I define on the interactive top level.
Sorry if the answer is obvious - hard to search for this! Thanks.
The standard trick for this is to make a new module synonym:
# module Mylist = List;;
module Mylist :
sig
val length : 'a list -> int
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
. . .
val sort : ('a -> 'a -> int) -> 'a list -> 'a list
val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
end
#
Update
Since OCaml 4.02 this trick no longer works. Instead there is a toplevel directive for the purpose:
# #show_module List;;
module List :
sig
val length : 'a list -> int
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
. . .
val sort : ('a -> 'a -> int) -> 'a list -> 'a list
val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list
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
In OCaml versions >= 4.02, you can now also do this in the interactive interpreter:
# #show_module List;;
module List :
sig
val length : 'a list -> int
...
end
Or just use #show List;;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With