Adding type annotations to an AST?

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

Partially answering my own question - it seems like I want "type directed translation" as per section 8 of "Practical Type Inference for Arbitrary Ranked Types". Does anyone know of a presentation with a simpler type language? Thanks again Stephen

Hi Stephen, On Mon, Mar 5, 2012 at 08:52, Stephen Tetley wrote:
How do I add type annotations to interior locations in an abstract syntax tree?
I use an annotated expression tree in my work. The nodes of the AST are annotated with the type, assumption set, and constraint set as described in constraint-based type inference [1]. We have a paper describing our type-and-transform system [2] and a link in the paper points to the code. Let me know if you have any questions. Regards, Sean [1] http://www.staff.science.uu.nl/~heere112/phdthesis/index.html [2] http://www.cs.uu.nl/research/techreps/UU-CS-2012-004.html

Hi Sean Many thanks - the note on flow-issues might be particularly helpful for me (last para section 4 introduction). My current code has a bug which maybe this identifies. I'm currently using a modified algorithm M which I believe is top down, I'll switch to algorithm W. Thanks again Stephen
participants (2)
-
Sean Leather
-
Stephen Tetley