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
- take a *.ml file
- parse it
- run the type inference algorithm on it
- print out a typed ast tree, where each node also has an inferred type attached to it
Thanks!
nojb
2
You can use the -dtypedtree
flag to dump the typed AST after typechecking.
Cheers,
Nicolas
-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.