*.ml -> Typed AST Tree, where each node has inferred type

This is a followup to Questions regarding `ocamlc -dparsetree hello.ml` .

In the previous thread, we take a *.ml file, parse it, and print it.

I am wondering if there is a simple way to get a bit more information. I would like to

  1. take a *.ml file
  2. parse it
  3. run the type inference algorithm on it
  4. print out a typed ast tree, where each node also has an inferred type attached to it


You can use the -dtypedtree flag to dump the typed AST after typechecking.


-dtypedtree is a debug output, it is not really a dump of the typed AST.

But as previously, the generic answer is that yes, it is possible using the compiler libraries to reproduce any part of the compiler pipeline.

However, that sounds a lot like a XY problem to me: it is unclear to me what you intend to do with a printed typed AST.

See how difficult it is to transpile a limited set of OCaml to GoLang / Julia.