Generic types

I have defined a language within MPS that allows for generic type definitions like these:

List <Elem> ::= NILL <no fields>| 
CONS { head :: Elem; tail :: List <Elem> }

With some effort, I have managed to get the typesystem working to correctly assign types to expressions using these types, but they are all deleted before I can use them in the generator.

The difficult part of typing generic constructors are expressions like NILL, which is a list of some element type, but the element type needs to be inferred from the surrounding context. To get this working I probably misused the typevariable system a bit. The typesystem seems to rely on the fact that all typevariables are directly assigned as the type of some node, and it does not allow a typing rule that states something like:

Typevar T;

typeof(Constructor) :==: List<T>

Nothing crashes, I can successfully acces the types of nodes in checking rules, and the typesystem dubug features also show the correct type. The problem is that I need this type information during the generator step, and by then all types of NILL nodes have been replaced with nullpointers. This also happens when I created a new generator stage which I set to run before all others, and only print the type of all NILL nodes. This means something is throwing the type nodes away between the typechecking and generation phases.

I have run out of ideas to try at this point, and any help or insight is appreciated.

Please sign in to leave a comment.