Type Statements
Type Statements
Type statements define custom types that can be used for concept declarations. This enables semantic typing and type aliases.
Tips
There are standard types defined in the std. library imports included with trilogy. These are suggested default integration targets, though users can create/extend their own.
Syntax
type_declaration: "type" IDENTIFIER data_type ("|" data_type)* type_drop_clause?
type_drop_clause: "DROP" IDENTIFIER ("|" IDENTIFIER)*
Basic Type Alias
Create an alias for an existing type:
type currency float;
type email string;
type phone_number string;
Union Types
Define a type that can be one of several base types:
type identifier int | string;
Using Custom Types
Apply custom types to concepts:
type currency float;
type email string;
key customer_id int;
property customer_id.email email;
property customer_id.balance currency;
Semantic Types
Use types to add semantic meaning:
type usd float;
type eur float;
type percentage float;
property order_id.total usd;
property order_id.tax_rate percentage;
Use Cases
- Domain modeling
- Type safety
- Documentation through types
- Standardizing data formats
- Semantic layer enrichment
Example
# Define semantic types
type customer_id int;
type order_id int;
type usd float;
type email_address string;
# Use types in definitions
key cid customer_id;
key oid order_id;
property cid.email email_address;
property cid.balance usd;
property oid.total usd;
property oid.customer customer_id;
Tips
Custom types help document intent and can enable tooling to provide better validation, code completion - and rendering.
Trilogy studio relies heavily on them to provide better default visualizations.
