The Ast.expr
type definition looks wrong: it does not represent an abstract syntax tree, but merely the syntax of an atomic expression. This is because the type is not recursive at all, so it can hardly be called a tree. By comparison, Sexp.expr
is a recursive type.
My guess is that you forgot a case in the type definition, for instance:
type expr =
| Expr_unit
| Expr_int of int
| Expr_sym of sym
| Expr_call of expr list
Once this is done, the two types are practically the same, so conversion becomes simple.