gsdlab / clafer

Clafer is a lightweight modeling language
http://clafer.org
MIT License
45 stars 13 forks source link

Allow inheritance from concrete clafers #82

Open mantkiew opened 8 years ago

mantkiew commented 8 years ago

In order to fully support example-driven modeling, every instance of a Clafer model must be a valid model itself, which reproduces exactly that single instance. For example, for a model:

a -> integer 2
   b -> a ?

A possible instance is

a$1 : a -> 5
    b$1 : b -> a$2
a$2 : a -> 6

Note, the instance generators would have to begin using -> 5 instead of = 5, as currently for values.

To allow the instance to always be a valid model (in a sense that when I copy paste the instance into a model, it should just compile and IG should always reproduce the same instance), clafers must be allowed to inherit from concrete clafers: a$1 : a, a$2 : a, and b$1 : b.

So this should be a valid model:

a -> integer 2
   b -> a ?

a$1 : a -> 5
    b$1 : b -> a$2
a$2 : a -> 6

for which the instance generator should produce exactly this instance:

a$1 : a -> 5
    b$1 : b -> a$2
a$2 : a -> 6

Implementation

There are a few considerations

1) allow $<num> in clafer names 2) disallow group cardinality refinement 3) allow adding new children as usual 4) instance generator should not add additional numerals to names, so that we don't end up with a$1$1 and a$2$1. The names which include the $<num> will be required to be unique and checked, therefore IG will not have to add new suffixes.

So, the users should be able to then take a generated instance an edit. There are two reasons:

1) just add more detail, like new children 2) remove detail to create a partial instance

For example, consider this changed model

a$1 : a                      // removed concrete value
    b$1 : b -> a$2
        c                        // added a child
a$2 : a -> 6
     d