0
votes

Is there any way to extract all the type definitions from a bunch of OCaml files? I can always cut and paste them into a separate editor tab, where it's easy to stare at them in a way that fits as much information on the screen at possible. However, this is a chore and I'd prefer to make it automated.

To make it precise, Emacs and tuareg mode already shows me the types of all the functions, but what I'd also want is to be able to collect a nice cheat sheet of what each type actually is. For modules, there's obviously the mli-file, but for everything else collecting them into one place to quickly get an overview of a bunch of code is annoying.

1
doesn't fhe language have a parser for itself? btw I would avoid asking about tools in a SO thread — that's like begging for a Closed as Off Topic. - Erik Kaplun
Yes, of course I could grab the source code of the parser and write it myself. However, I have other things on my plate and was hoping there is a way to do this and that has already been implemented by someone. - Edvard Fagerholm
@Erik: Well, I'm not asking "what's the best tool/ide/...", which tend to get closed. However, I'm usually a bad judge regarding what people think of as off-topic, so I don't care. - Edvard Fagerholm
Generate mli with ocamlc -i or use ocamldoc - camlspotter
I think you need to give an example of what you expect for us to understand what you mean. - didierc

1 Answers

1
votes

It's very difficult to understand what you're asking for. Maybe it will help if I collect everybody's suggestions into one place.

As nlucaroni points out, you can't say you have a solution for modules but you want something that works for everything else. There is nothing else. All OCaml code is part of a module.

You say that mli files are OK. If a module doesn't have an mli file, you can generate an mli file for it with ocamlc -i as camlspotter says.

If this doesn't work, give an example of some OCaml code and what extracted definitions you want to see for it.