Creating a type hierarchy

Hello.

I am trying to create a language which has types such as Any, String, Number etc. I created the concepts AnyType, StringType, NumberType. Now I would like to create typing rules, such as "type of node foo is StringType" or "StingType is subtype of AnyType". However, I cannot enter equations, such as "typeOf(node) :==: <StringType>". The auto completion menu does not offer me any of the types or concepts in my language, only stuff from BaseLanguage. How can I reference my types and concepts from type expression language?

Margus

P.S. the MPS itself is quite cool. :-)

5 comments
Comment actions Permalink

Hello, Margus,

In order to accomplish what you want, you need to create a subtyping rule. There are plenty of them in the base language so you can use them as a reference. You can create them from the new root node popup menu. I also strongly recommend you reading the chapter on the typesystem in our MPS user's guide here: http://www.jetbrains.net/confluence/display/MPS/Typesystem

Regards,

Konstantin

0
Comment actions Permalink

Yes, I looked at the documentation and the base language. My problem was creation of concept literals. I discovered that they can be constructed using concept/Foo/ syntax and now my type hierarchy seems to work.

0
Comment actions Permalink

Hi, Margus,

We usually have node instances as type, not concepts. For example, we have IntType concept which is used as concept.

Konstantin

0
Comment actions Permalink

Sorry, this is a bit confusing (too many instances of word "concept").

I am trying to create a type system which is modeled by concepts, such as NumberType, StringType, etc. This seems to match what is done in the base language. Now, when I assign types to node instances, what should I use? Currently I have concept NumberLiteral whose type constraint looks like this:

rule typeof_NumberLiteral {                      
   applicable for concept = NumberLiteral as value
   overrides false                                     
   child type restrictions << ... >>                   
                                                       
   do {                                                
      typeof ( value ) :==: concept / NumberType / ;
   }                                                   
}

Is this incorrect? If so, how should I write it?

Margus

0
Comment actions Permalink

Margus,

It's correct, but I would write

      typeof ( value ) :==: new node<NodeType>();

Konstantin

0

Please sign in to leave a comment.