Friday, May 22, 2009
Ewald on Dynamic languages
What's the purpose of types?
Structural versus Nominal typing
M Past and Present
Let's talk a little about M's past and present.
At PDC 08, we introduced M as a way to write down data (Mgraph), schema and functions about that structured data (Mschema), and character parsing into structured data (Mgrammar).
Frankly, at PDC, we tried to tell a '1 language with 3 parts' story, but in my opinion it was more like a '2 languages with similar concepts and marketing terms'. Truth be told, those technologies kinda grew up separate.
It doesn't matter. We showed the world some interesting ideas, and we saw how powerful it could be to bring the pieces together.
We've been working hard at that - at integrating the languages. As I type, some of the smartest folks I know are busy rebuilding the internals of the compiler. We hope to be able to bring all of the parts together as close as we can before the next PDC. I can't wait to illustrate some of the key customer scenarios we expect to get with that integration.
Our first step to integrate the language will be visible to everyone in our next CTP drop. We deleted mg.exe, the compiler tool for Mgrammar. Now, you can use a single executable and API to compile Mschema or Mgrammar programs. You still have to have separate file extensions (.mg for Mgrammar, .m for Mschema).
We almost deleted mgx.exe as well, but we weren't able to get all of that work done.
Now - what happens after we integrate the language? I'll talk more about that in the future. And, I'll talk about other innovations we'll be seeing in the language - some of them before PDC 09, but maybe not until after.
Stay tuned.
Saturday, May 16, 2009
"Reflection" in M
The M catalog is simply a structured representation of an M program, or what we call the M semantic graph. The schema for the catalog is written in M, and the compiler can generate instances of your M program into that schema. Then it just shows up in the database using mx.exe.
Right now, the way to create an image with the M catalog schema is to run m.exe with the 'catalog definition' parameter, or 'catdef' for short.
m.exe -catdef -out:catalog.mx
This creates an image that contains extent declarations for things like Modules, Types, Extents, and Computed Values. The catalog also has various helper computed values for querying the catalog. For example, you can ask if a particular computed value is installed (IsComputedValueInstalled). Or, you can ask if a type is an intrinsic, collection or entity type (IsIntrinsicType, IsCollectionType, IsEntityType). Or, one of my favorite, you can ask for all of the references to an extent ('ReferencesToExtent').
For now, we don't automatically generate instances for a given M program. You have to explicitly ask for it, and you have to reference the catalog definition generated above. We hope to fix all of that in the next milestone and turn it on by default. Here's a simple example for how to create catalog instances for your M:
m.exe myM.m -catalog /r:catalog.mx
When you run mx with myM.mx and catalog.mx, the M catalog will show up in the database. After you load, take a look at the database. In particular, one super cool thing is that the catalog also maintains the relationship between the SQL created from the M and their corresponding M declarations. For example, take a look at Tables, Functions, and Views in the Language.Catalog.SQL namespace.
That's a brief intro to the M catalog. There will be lots of scenarios coming where we use the catalog to query, analyze and understand M.
What if you want to access the catalog from your M program? That's easy enough because the catalog is written in M. So, you can reference and query the extents directly, or call one of the computed values.
The coolest reason to do this is to add additional data to your M program. This is what some people call metadata - although I'm not very fond of that term (it's all just data). Let's start with an example.
Let's start with one of our classic Oslo scenario models, the WIX model. Let's suppose that I am building a super-duper add-in to WIX that will deploy M to a database. The problem is that the WIX model does not include database deployment information. I could update the WIX model to include this, but that's not a great extensibility story for our developers. Instead, I will build my own little model for my specialization, I will reference M content in the catalog, and I will use about to write instances that reference specific values in the catalog.
Here's a simple version of my model. It describes additional information that I want to associate with a module in M:
module MDeployer
{
import Language.Catalog;
DatabaseConfigurations : ({
Id : Integer32 => AutoNumber;
DatabaseName : Text;
ServerName : Text;
Module : Modules;
} where identity Id, value.Module in Modules)*;
}
Now, I want to write a deployment package the says that a particular M module is deployed to a particular server and database. Here's an example, except what do I write to specify the module name?
module DeploymentPackage
{
import MDeployer;
import MyModel;
MDeployer::DatabaseConfigurations
{
{ DatabaseName => "Testdatabase", ServerName => "TestServer", Module => ... }
}
}
You could write a query, for example, 'Module => (Modules where value.Name == "MyModel")'. That's not always easy to remember. What's worse is that it is not strongly typed - what if I misspell "MyModel". I wouldn't find out about that until loading into the database. What I really want is a compile-time check that I have referenced the right M declaration.
'about' is the magic to make this easy. 'about' is a function that does what the query does, but it's strongly typed and uses the actual identifiers of the M declaration that you want to reference. Here it is:
module DeploymentPackage
{
import MDeployer;
import MyModel;
MDeployer::Databases
{
{
DatabaseName => "Testdatabase",
ServerName => "TestServer",
Module => about(MyModel)
}
}
}
In summary, about allows you to add additional data to your M that is about your M. It references that content, and when loaded to the database, references your M program that is represented in the M catalog.