Home > Articles > Programming

The Oslo Modeling Language: An Introduction to "M"

M--a modern, declarative language for working with data--was designed to allow users to write down what they want from their data without having to specify how those desires are met against a given technology or platform. This chapter provides an introduction to M.
This chapter is from the book

The “Oslo” Modeling Language (M) is a modern, declarative language for working with data. M lets users write down how they want to structure and query their data using a convenient textual syntax that is convenient to both author and read.

M does not mandate how data is stored or accessed, nor does it mandate a specific implementation technology. Rather, M was designed to allow users to write down what they want from their data without having to specify how those desires are met against a given technology or platform. That stated, M in no way prohibits implementations from providing rich declarative or imperative support for controlling how M constructs are represented and executed in a given environment.

M builds on three basic concepts: values, types, and extents. Here’s how M defines these three concepts:

  1. A value is simply data that conforms to the rules of the M language.
  2. A type describes a set of values.
  3. An extent provides dynamic storage for values.

In general, M separates the typing of data from the storage/extent of the data. A given type can be used to describe data from multiple extents as well as to describe the results of a calculation. This allows users to start writing down types first and decide where to put or calculate the corresponding values later.

On the topic of determining where to put values, the M language does not specify how an implementation maps a declared extent to an external store such as an RDBMS. However, M was designed to make such implementations possible and is compatible with the relational model.

Another important aspect of data management that M does not address is that of update. M is a functional language that does not have constructs for changing the contents of an extent. How data changes is outside the scope of the language. That said, M anticipates that the contents of an extent can change via external (to M) stimuli. Subsequent versions of M are expected to provide declarative constructs for updating data.

This chapter provides a non-normative introduction to the fundamental concepts in M. Chapters 2-6 provide the normative definition of the language.

1.1 Values

The easiest way to get started with M is to look at some values. M has intrinsic support for constructing values. The following is a legal value in M:

"Hello, world"

The quotation marks tell M that this is the text value Hello, world. M literals can also be numbers. The following literal:

1

is the numeric value one. Finally, there are two literals that represent logical values:

true
false

We’ve just seen examples of using literals to write down textual, numeric, and logical values. We can also use expressions to write down values that are computed.

An M expression applies an operator to zero or more operands to produce a result. An operator is either a built-in operator (e.g., +) or a user-defined function (which we look at in Section 1.2.5). An operand is a value that is used by the operator to calculate the result of the expression, which is itself a value. Expressions nest, so the operands themselves can be expressions.

M defines two equality operators: equals, ==, and not equals, !=, both of which result in either true or false based on the equivalence/nonequivalence of the two operands. Here are some expressions that use the equality operators:

1 == 1
"Hello" != "hELLO"
true != false

All of these expressions will yield the value true when evaluated.

M defines the standard four relational operators, less-than <, greater-than >, less-than-or-equal <=, and greater-than-or-equal >=, which work over numeric and textual values. M also defines the standard three logical operators: and &&, or ||, and not ! that combine logical values.

The following expressions show these operators in action:

1 < 4
1 == 1
1 < 4 != 1 > 4
!(1 + 1 == 3)
(1 + 1 == 3) || (2 + 2 < 10)
(1 + 1 == 2) && (2 + 2 < 10)

Again, all of these expressions yield the value true when evaluated.

1.1.1 Collections

All of the values we saw in the previous section were simple values. In M, a simple value is a value that has no uniform way to be decomposed into constituent parts. While there are textual operators that allow you to extract substrings from a text value, those operators are specific to textual data and don’t work on numeric data. Similarly, any “bit-level” operations on binary values don’t apply to text or numeric data.

An M collection is a value that groups together zero or more elements that themselves are values. We can write down collections in expressions using an initializer, { }.

The following expressions each use an initializer to yield a collection value:

{ 1, 2 }
{ 1 }
{ }

As with simple values, the equivalence operators == and != are defined over collections. In M, two collections are considered equivalent if and only if each element has a distinct equivalent element in the other collection. That allows us to write the following equivalence expressions:

{ 1, 2 } == { 1, 2 }
{ 1, 2 } != { 1 }

both of which are true.

The elements of a collection can consist of different kinds of values:

{ true, "Hello" }

and these values can be the result of arbitrary calculation:

{ 1 + 2, 99 – 3, 4 < 9 }

which is equivalent to the collection:

{ 3, 96, true }.

The order of elements in a collection is not significant. That means that the following expression is also true:

{ 1, 2 } == { 2, 1 }

Finally, collections can contain duplicate elements, which are significant. That makes the following expression:

{ 1, 2, 2 } != { 1, 2 }

also true.

M defines a set of built-in operators that are specific to collections. The most important is the in operator, which tests whether a given value is an element of the collection. The result of the in operator is a logical value that indicates whether the value is or is not an element of the collection. For example, these expressions:

1 in { 1, 2, 3 }
!(1 in { "Hello", 9 })

both result in true.

M defines a Count member on collections that calculates the number of elements in a collection. This use of that operator:

{ 1, 2, 2, 3 }.Count

results in the value 4. The postfix # operator returns the count of a collection, so

{ 1, 2, 2, 3 }# == { 1, 2, 2, 3 }.Count

returns true.

As noted earlier, M collections may contain duplicates. You can apply the Distinct member to get a version of the collection with any duplicates removed:

{ 1, 2, 3, 1 }.Distinct == { 1, 2, 3 }

The result of Distinct is not just a collection but is also a set, that is, a collection of distinct elements.

M also defines set union "|" and set intersection "&" operators, which also yield sets:

({ 1, 2, 3, 1 } | { 1, 2, 4 }) == { 1, 2, 3, 4 }
({ 1, 2, 3, 1 } & { 1, 2, 4 }) == { 1, 2 }

Note that union and intersection always return collections that are sets, even when applied to collections that contain duplicates.

M defines the subset and superset using <= and >=. Again these operations convert collections to sets. The following expressions evaluate to true.

{ 1, 2 } <= { 1, 2, 3 }
{ "Hello", "World" } >= { "World" }
{ 1, 2, 1 } <= { 1, 2, 3 }

Arguably the most commonly used collection operator is the where operator. The where operator applies a logical expression (called the predicate) to each element in a collection (called the domain) and results in a new collection that consists of only the elements for which the predicate holds true. To allow the element to be used in the predicate, the where operator introduces the symbol value to stand in for the specific element being tested.

For example, consider this expression that uses a where operator:

{ 1, 2, 3, 4, 5, 6 } where value > 3

In this example, the domain is the collection { 1, 2, 3, 4, 5, 6 } and the predicate is the expression value > 3. Note that the identifier value is available only within the scope of the predicate expression. The result of this expression is the collection { 4, 5, 6 }.

M supports a richer set of query comprehensions using a syntax similar to that of Language Integrated Query (LINQ). For example, the where example just shown can be written in long form as follows:

from value in { 1, 2, 3, 4, 5, 6 }
where value > 3
select value

In general, M supports the LINQ operators with these significant exceptions:

  1. ElementAt/First/Last/Range/Skip are not supported—M collections are unordered and do not support positional access to elements.
  2. Reverse is not supported—Again, position is not significant on M collections.
  3. Take/TakeWhile/Single—These operators do not exist in M.
  4. Choose—This selects an arbitrary element.
  5. ToArray/ToDictionary/ToList—There are no corresponding CLR types in M.
  6. Cast-typing works differently in M—You can achieve the same effect using a where operator.

While the where operator allows elements to be accessed based on a calculation over the values of each element, there are situations where it would be much more convenient to simply assign names to each element and then access the element values by its assigned name. M defines a distinct kind of value called an entity for just this purpose.

1.1.2 Entities

An entity consists of zero or more name-value pairs called fields. Entities can be constructed in M using an initializer. Here’s a simple entity value:

{ X = 100, Y = 200 }

This entity has two fields: one named X with the value of 100, the other named Y with the value of 200.

Entity initializers can use arbitrary expressions as field values:

{ X = 50 + 50, Y = 300 - 100 }

And the names of members can be arbitrary Unicode text:

{
  [Horizontal Coordinate] = 100,
  [Vertical Coordinate] = 200
}

If the member name matches the Identifier pattern, it can be written without the surrounding [ ]. An identifier must begin with an upper or lowercase letter or "_" and be followed by a sequence of letters, digits, "_", and "$".

Here are a few examples:

HelloWorld = 1     // matches the Identifier pattern
[Hello World] = 1  // doesn't match identifier pattern
_HelloWorld = 1    // matches the Identifier pattern
A = 1              // matches the Identifier pattern
[1] = 1            // doesn't match identifier pattern

It is always legal to use [ ] to escape symbolic names; however, most of the examples in this document use names that don’t require escaping and, therefore, do not use escaping syntax for readability.

M imposes no limitations on the values of entity members. It is legal for the value of an entity member to refer to another entity:

{
  TopLeft = { X = 100, Y = 200 },
  BottomRight = { X = 400, Y = 100 }
}

or a collection:

{
  LotteryPicks = { 1, 18, 25, 32, 55, 61 },
  Odds = 0.00000001
}

or a collection of entities:

{
  Color = "Red",
  Path = {
    { X = 100, Y = 100 },
    { X = 200, Y = 200 },
    { X = 300, Y = 100 },
    { X = 300, Y = 100 },
  }
}

This last example illustrates that entity values are legal for use as elements in collections.

Entity initializers are useful for constructing new entity values. M defines the dot, “.”, operator over entities for accessing the value of a given member. For example, this expression:

{ X = 100, Y = 200 }.X

yields the value of the X member, which in this case is 100. The result of the dot operator is just a value that is subject to subsequent operations. For example, this expression:

{ Center = { X = 100, Y = 200 }, Radius = 3 }.Center.Y

yields the value 200.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020