Bernard James POPE (firstname.lastname@example.org.OZ.AU)
Wed, 16 Aug 2000 19:07:13 +1000 (EST)
Hi all, I want to use the typechecker of nhc98 to infer the types of variables within my haskell source, ultimately so that I can annnotate a parse tree of the original program with type signatures inferred from the type-checking phase of the compiler. It is important for my task that I don't modify the parse tree in any significant way, b/c I want to maintain the structure and names of the original code. My main problem is that variable names are modified by the renamer before type inference/checking is performed. So for this code: foo = let x1 = app addThree 1 2 3 in let x2 = app inc 2 in x1 + x2 The variable x1 gets renamed to "Main.Prelude.166.x1" (by observing the symbol table after renaming). Of course this would be impossible to distinguish from other letbound variables called x1 elsewhere in the same module, if I didn't know how they were renamed. I looked at the renaming code and I noticed that uniqueTid is called with the position of the identifier. My proposed scheme is to incoporate the position of the variable into the unique name generated so that from the original parse tree I can find the occurrence of each variable in the symbol table after renaming and typechecking has occurred. So for example, let's say that x1 occurs at position (row 17, col 13) in module Main, then the unique name generated for x1 could be something like "Main.Prelude.166.17-13.x1" uniquely identify each identifier. Each identifier I find in the initial parse tree can be looked up in the symbol table after renaming and type-checking by using the module name and the row and column information. I realise this is a bit of a hack, and it might break some of the assumptions about the naming scheme in other parts of the compiler. So before I go ahead, I wanted to know whether this was a reasonable approach, and if not are there any other avenues I could pursue? Regards, Bernie.