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 a custom type as a trait on its base type with base_type::trait:
type currency float;
type email string;
key customer_id int;
property customer_id.email string::email;
property customer_id.balance float::currency;
Semantic Types
Use types to add semantic meaning:
type usd float;
type eur float;
type percentage float;
property order_id.total float::usd;
property order_id.tax_rate float::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 int::customer_id;
key oid int::order_id;
property cid.email string::email_address;
property cid.balance float::usd;
property oid.total float::usd;
property oid.customer int::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.