liveBook · Manning

Assignment compatibility

As explained in Building User-Friendly DSLs

A directional type relation in which every value of one type can be assigned as a value of another type.

Assignment compatibility is directional: type T is assignable to type U when every T value can be assigned as a U value. The reverse relation does not automatically hold. section 13.3

The implementation uses a simpler compatibility rule: types match when their type-object IDs are equal. Assignability also provides a broader way to describe inheritance and type coercion. section 13.3

Type objects support compatibility checks throughout the language implementation:

  • Compare type-object IDs instead of relying on JavaScript object equality. section 13.3
  • Propagate equality checks into attribute constraints and report mismatched types using readable type names. section 13.3
  • Use compatible built-in types to control number rendering, including dollar, day, and percentage markers. section 13.3

Attribute and value compatibility

When an attribute and its value are both typed, the constraint checker compares their type objects. A mismatch produces an issue stating that the types must match and displaying both types. section 13.3

Table 13.1 The type objects for built-in types
Type name
ID
Concept label
Settings
amount
numberType_amount
Number Type
{ "unit": "$" }
date range
numberType_dateRange
Interval Type
{ "unit": "day" }
percentage
numberType_percentage
Number Type
{ "unit": "%" }
untype
untype_untype
Untype
{}

Built-in type objects make compatibility concrete: amount, date range, percentage, and untype each have a distinct ID and representation. section 13.3

How Building User-Friendly DSLs covers it

How deep it goes
Defines directional assignability but implements only equality-based compatibility, deferring richer subtype and coercion rules.
Examples
Demonstrates built-in amount, date range, percentage, and untype objects plus attribute-value mismatch reporting.
What it assumes
Assumes basic types and values, while defining directional assignability and showing type objects from implementation level.
What you can do after
Diagnose typed attribute mismatches and understand how type-object equality controls validation and number rendering.
How it connects
Connects assignment compatibility with type equality, inheritance, type coercion, type objects, and constraints checking.

Also explained in

Compare how 3 books explain assignment compatibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.