objmagic
objmagic

Reputation: 1028

How to print typed parse tree

-dparsetree can be used to print untyped parse tree, but how can one print typed AST in OCaml? I looked into the typing directory in the source code, it seems that some functions can do this.

Upvotes: 2

Views: 857

Answers (1)

camlspotter
camlspotter

Reputation: 9030

Use -dtypedtree. It is a newer feature than -dparsetree and introduced from 4.01.0. You need to upgrade your compiler if ocamlc does not have it.

Unfortunately -dtypedtree does not show the type information of the typed AST. I am afraid there is no option or tool to print it with type information currently. Probably since printing all the type info attached to the subnodes is too hard to read, I am afraid. For example, even a simple code let f x = x + 1 has the following typed AST:

let (f : int -> int) =
  (fun (x : int) ->  
    (( ( (+) : int -> int -> int) (x : int) : int -> int) (1 : int) : int) : int -> int)

The best way is to write your own printer of typed AST which only prints types of your interest.

Upvotes: 1

Related Questions