Is it possible to parametrize concept with another concept (generic concept)?

Hello!

I'm looking an ability to specify a generic parameter to a concept.
I'm implementing some YAML-based DSL. YAML allows to include any part of its content from the separate file and I'd like to implement this in MPS editor as well.

Here is my sample.
Root concept has a child "documentation". It's target may be either inline documentation or included documentation. Inline documentation has a body, included documentation has a reference to a documentation file. Documentation file is also root concept, that has documentation body as its child.
I'd like to parametrize concepts Inline, Include and File with DocumentationBody to reuse for another root's child.

Is it possible?

Thanks, Alexey
5 comments
Sorry, haven't understood what should this "parameterization" change.

Am I right you are asking about "how to force creating a specific child (DocumentationBody) when an instance of its parent is created in editor (Inline, Include, File)"?
In this case, the answer is "yes", the right way to do this is NodeFactories in Editor aspect of a language.
0
I'll try to simplify my sample.
What I want to create is:
concept File<T> implements INamedConcept
File has one child:
body: T of cardinality [1]
prettyPrint();
File has an editor like this:
name: {name}
%body%
prettyPrint();
Then I'd like to create DocReference concept with reference ref: File<DocumentBody> and create instances (somehow) of File<DocumentBody> in my solution.

While writing this description I've found a possible solution. I'll add a reference to File called "type" with target ConceptDeclaration. I'm not sure, that it is a "good solution"...
0
I think, I've solved my problem. File concept has a 'body' child of type Includable (some interface concept). And reference to that File has constraint that filters search scope to select only files with bodies of necessary concept.
0
Yep, I think, this is correct.
We don't have "generic parameters" in concepts as it's not clear where they should be taken into account, instead, you specify the precise behavior you want to get in the corresponding aspect.
0

Hi,

I also find myself needing generic concepts. Something like

concept List<T> extends BaseConcept

children:
elements : T[0..n]

My main motivation is code reuse and extensibility. I want to allow extensions of my language to reuse my `List` concept with their own element types.

I don't see how to adapt @apomelov's solution, since `List`'s type parameter may be instantiated not only to a concrete type, but also to a type argument of the containing concept:

concept Foo<T> extends BaseConcept

children:
list : List<T>[1]

 

> We don't have "generic parameters" in concepts as it's not clear where they should be taken into account

I admit I don't understand what the problem with generic concepts would be.

0

Please sign in to leave a comment.