Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

examine library (.cma) signature from console

Tags:

ocaml

Say I have an OCaml library file foo.cma. Is there a command line tool to print the signature of the functions and other types defined there ? The ocamlbrowser utility seems to be windows-based (complains about the $DISPLAY environment variable). The use case is that I am doing a:

ocamlc -c foo.cma main.ml

and get:

File "main.ml", line 13, characters 33-47:
Error: Unbound value ListUtil.split

ListUtil.split ought to reside in foo.cma but I don't know a console-based tool to verify it.

like image 631
Marcus Junius Brutus Avatar asked Mar 19 '12 11:03

Marcus Junius Brutus


3 Answers

On Debian/Ubuntu, you have "ocamlobjinfo":

ocamlobjinfo stdlib.cma

will display all the unit names included in stdlib.cma. Then, you can create a short file:

include SomeModule

and compile it with -i to see what is defined in module SomeModule.

like image 159
Fabrice Le Fessant Avatar answered Oct 26 '22 08:10

Fabrice Le Fessant


In the toplevel, I just load the cma file:

#load "foo.cma";;

Then I re-defined a module just to see the signature:

module Chunk = Foo;;
like image 31
Çağdaş Bozman Avatar answered Oct 26 '22 08:10

Çağdaş Bozman


In order to compile the code referencing ListUtil.split the compiler needs to find the corresponding listUtil.cmi file. In order to link that code compiler will need the cma (or cmo) file containing the implementation. See http://mirror.ocamlcore.org/caml.inria.fr/pub/ml-archives/caml-list/2008/09/2bc9b38171177af5dc0d832a365d290d.en.html for some explanation.

like image 21
ygrek Avatar answered Oct 26 '22 08:10

ygrek