[This is prerelease documentation and is subject to change in future releases. Blank topics are included as placeholders.]
This tutorial is an introduction to refinement in Microsoft code name “M”. After reading this tutorial, you should know how to extend existing “M” types for your applications.
What is Refinement?
Refinement is when you take an existing simple or derived type and add additional constraints on it. Refinement may be done to create a new derived type, or it may be done within the context of a single collection.
Refining Derived Types
In this section, you will refine a sample derived type. You can also use the Visual Studio extensions for “M”.
To code the refined derived types
Open the “Intellipad” editor by clicking Start -> All Programs -> Microsoft Oslo SDK -> Tools -> Intellipad. The editor window appears.
Add the following code fragment, which is the smallest possible “M” program, because every “M” statement must be contained inside a module.
Add the following code fragment inside the braces of the module statement. This adds a type that is refined in step 4.
type Employee{
Name : Text;
ID : Integer32;
}
After the Employee type declaration, add the following code fragment. This refines Employee so that there is a new type, MyEmployee, that has more specific type requirements for Name and ID.
type MyEmployee = Employee where value.Name in Text && value.ID in Number;
After the MyEmployee type declaration, add the following the code fragment. This further refines the type so that all MyEmployee2 instances must have an ID greater than 20.
type MyEmployee2 : MyEmployee where value.ID > 20;
Refining Intrinsic Types
In this section, you will refine the intrinsic type Number to create a new derived type, PositiveNumber, that only accepts non-negative numbers.
To code the refined intrinsic type
After the MyEmployee2 type declaration, add the following code fragment.
type PositiveNumber : Number where value >= 0
Complete Code
Here is the complete code after finishing this tutorial.
module Southwind
{
type Employee
{
Name : Text;
ID : Integer32;
}
type MyEmployee : Employee where value.Name in Text && value.ID in Number;
type MyEmployee2 : MyEmployee where value.ID > 20;
type PositiveNumber : Number where value >= 0;
}