Overview

The design of MUFL makes an important distinction between two types of data classification: domains and types.

In short, a domain is a runtime concept; a type is a compile-time concept.

While both types and domains ultimately represent sets of values, types are sets known and checked at compile time, whereas domains are sets that share a certain implementation and are only verified at run time. For example, a domain mismatch (such as attempting to subscript an integer) leads to a runtime error, while a type mismatch leads to a compile-time error.

Motivation

MUFL is a high-level interpreted language and relies on certain low-level code to provide implementation of data-related operations. For example, consider string data. The implementation of the string driver in MUFL is a single C++ class that can handle strings of any length. However, at the MUFL language level, it might be useful to limit strings to a length of, say, 10 characters. The MUFL compiler regards data as a high-level concept, whereas the MUFL evaluation environment is tasked with carrying out the compiler’s instructions at the low-level.

In MUFL, domains correspond one-to-one to the C++ class within the ADAPT evaluation environment that provides a driver for handling a certain kind of data (integers, strings), while types govern the information known about the data at compile time.

Types don’t have to correspond to domains exactly, because at compile time, certain data might have restrictions in addition to the restrictions established by its domain implementation (say, a string with a limited length). Compile-time types might also span multiple domains (for example, “INTEGER or STRING”).

Example

In MUFL, INTEGER is a domain that consists of numbers. There is a corresponding type, int that designates the INTEGER domain as a compile-time type. But what if the programmer wants to have a variable that is “integer or nil” to allow for the possibility that the number might be unknown or missing?

The type int+ represents type [nullable integer][../mufl-language-reference/misc-type-expressions.md#nullable-types], which is a combination of two domain-corresponding types, int and nil.