Bourne shell script to print Merlin's inferred module sig of a file

merlin

#1

I managed to whip up a script to get the module signature of a file using Merlin’s (2.5.4 only) inference: https://gist.github.com/yawaramin/b86557ae81cbd019fcb9e071abe594de

You can use it like: sig src/foo.ml

And it will print the signature to stdout. This is useful for reading into an editor. E.g., with vim I can open a new signature file :e foo.mli and then do :r !sig % to immediately read in the signature.


#2

I think this could be simpler if you stick to merlin 3.0 and use $ ocamlmerlin single. Haven’t tried it though.


#3

Why don’t you use the -i option of the OCaml compiler ?

$ cat a.ml
type t = A
let v = A
let f = function A -> A

$ ocamlc -i a.ml
type t = A
val v : t
val f : t -> t

#4

Because there’s no convenient way to pass all the necessary options in a big project. Though it’s not even that hard, you can simply peek at jbuilder’s command log and repurpose one of the commands there.


#5

I frequently use cmitomli on files in _build/:
https://opam.ocaml.org/packages/cmitomli/


Merlin: Possible to view inferred interface/mli?