liveBook · Manning

Type object

As explained in Building User-Friendly DSLs

A machine-processable structured representation of a specific type, including an identifying concept label and settings.

A type object is a machine-processable representation of a specific type. It uses a concept label to identify the type class and settings to capture properties such as a unit. This structured form avoids fragile string manipulation and leaves room for hierarchies or parameterized types. section 13.3 section 13.4

A type object separates general type identity from type-specific settings:

  • Number Type with unit "$" represents amount; unit "%" represents percentage. section 13.3
  • Interval Type with unit "day" represents a date range whose values are date pairs. section 13.3
  • Untype represents the absence of a sensible computed type. section 13.3 section 13.4
  • Equality can use a stable identifier, while rendering converts the structured object back into readable type text. section 13.3

Using type objects during checking

Constraint checking computes the type of an attribute and the type of an AST value, compares the two type objects, and reports both rendered types when they differ. The same representations drive operator type computation and user-interface projections that display $, %, or days. section 13.3 section 13.4

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
{}

The built-in type table maps readable names to identifiers, concept labels, and settings. section 13.3

How Building User-Friendly DSLs covers it

How deep it goes
Defines structure, identifiers, equality, rendering, propagation, and fallback behavior without detailing a complete type-system theory.
Examples
Uses amount, percentage, date range, Number Type, Interval Type, Untype, and constraint-mismatch diagnostics.
What it assumes
Assumes familiarity with AST objects and expressions while teaching structured type representation instead of string-based types.
What you can do after
Build it from scratch: encode types as structured objects and use them for equality, inference, validation, and display.
How it connects
Connects type objects to AST objects, type inference, type checking, constraints, and type rendering.

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.