Anonymous Types (like c# or SQL)
Can someone please direct me to the feature(s) of mps typesystem that will allow me to create language that support "Anonymous Types"?
examples:
I read the docs, but I couldn't find what i was looking for. I will be happy if someone get direct me with the following:
Cheers (:
examples:
c#
in C#, visual studio + csc.exe (C# compiler) infer that type of the following expression:new { FirstName = "John", LastName = "Smith" }
is a type that contains 2 Fields: "String FirstName" and "String LastName" and provides all the necessary features regarding semantic checks, auto-complete and etc..SQL
in SQL, every FROM clause, JOIN clause and etc, can be modeled as a "chaining" of function that gets "tables" (list of type) and binary expressions as parameter, and type to "project" and returns "list" of type. for example:select u.FirstName, u.LastName, c.CityName from Users as u inner join Cities as c on c.CityId = u.CityId;can be modeled somthing like this:
Users.Join(
Cities,
{Users u,Cities c => c.CityId == u.CityId},
{Users u,Cities c => return new {u = u, c = c}}
)
.Select ( {UserAndCity => new
{
FirstName = UserAndCity.u.FirstName,
LastName = UserAndCity.u.LastName,
CityName = UserAndCity.c.CityName
}}
);
I read the docs, but I couldn't find what i was looking for. I will be happy if someone get direct me with the following:
- Can it be done in MPS?
- I want that for some language construct (Concepts) that their "attached types" will be inferred by a custom algorithm, that will inspect the child nodes and will "create dynamically" a type that is not explicitly defined. Which feature of MPS type-systems can I use to achieve it?
Cheers (:
Please sign in to leave a comment.
If you have already have a look to the type system section in the user guide, you should also read the cook book: http://confluence.jetbrains.com/display/MPSD30/Cookbook+-+Type+System
When you work for a while with MPS you will also recognize that many constructs you will use for your language description do not need a type declaration but MPS knows their types immediately.