
Hello All How do I add type annotations to interior locations in an abstract syntax tree? I have a small ML language where programs are a single expression, but the expression type has let-rec so it supports recursive function definitions. Source programs have no type annotations. I want to annotate the lec-rec with type annotations, but my type inference is a simple implementation of Algorithm J so it seems "monolithic" to me - i.e. the type it infers is the type of the whole program, I would also like the types of any internal let-rec definitions so I can label my AST. What is the idiom for accomplishing this? I'm using Eijiro Sumii's MinCaml as reference - this embeds mutable references for types in the AST. So this appears a non-starter. My other thought is to uniquely label all type locations during parsing then collect them in a map (location -> type) whilst computing the outermost type - I presume I can identify inner types as they are resolved during Algorithm J's run... Any solutions? Many thanks Stephen