Overview
The GLYPH type system provides formal definitions for all supported data types, including primitive types, collection types, and user-defined structures. This specification defines the type grammar, constraint system, and schema language.Primitive Types
Core Types
| Type | Description | Wire Format | Examples |
|---|---|---|---|
str | UTF-8 string | Bare or quoted | hello, "hello world" |
int | Signed 64-bit integer | Decimal | 42, -100, 0 |
float | IEEE 754 double | Shortest roundtrip | 3.14, 1e-06, 1e+15 |
bool | Boolean | t / f | t, f |
null | Null value | _ or ∅ | _ |
Extended Types
| Type | Description | Wire Format | Examples |
|---|---|---|---|
bytes | Binary data | Base64-encoded | b64"SGVsbG8=" |
time | Timestamp | ISO-8601 | 2025-01-13T12:00:00Z |
id | Typed reference | Prefix + value | ^user:abc123, ^org:acme |
blob | Large binary reference | Content-addressed | blob:sha256:abc123... |
Type Properties
Integer (int):
- Range: -2^63 to 2^63-1
- No leading zeros (except
0) - Decimal representation only (no hex/octal)
float):
- IEEE 754 double precision
- Exponent notation for
exp < -4orexp >= 15 - NaN and Infinity rejected
- Negative zero canonicalizes to
0
str):
- Valid UTF-8 required
- Bare-safe strings unquoted
- Quoted strings use minimal escapes
- No maximum length (implementation limits may apply)
time):
- ISO-8601 format with optional timezone
- Microsecond precision
- Canonical form uses
Zfor UTC
id):
- Format:
^prefix:value - Prefix: 1-12 lowercase letters
- Value: alphanumeric +
-+_ - Examples:
^user:123,^org:acme-corp
Collection Types
List
Syntax:[ + space-separated elements + ]
Properties:
- Ordered sequence
- Heterogeneous (elements can have different types)
- Zero-indexed
Map
Syntax:{ + sorted key=value pairs + }
Properties:
- Unordered key-value pairs
- Keys must be strings
- Keys sorted by UTF-8 byte order in canonical form
- Values can be any type
Struct
Syntax:TypeName{field=value ...} or TypeName:version{...}
Properties:
- Named type with versioning
- Defined fields with types
- Can be open (accepts unknown fields) or closed
Type Constraints
Integer Constraints
Syntax:int<min,max>
Examples:
String Constraints
Syntax:str<minlen,maxlen>
Examples:
Enum Constraints
Syntax:enum[value1,value2,...]
Examples:
List Constraints
Syntax:list<type, minlen, maxlen>
Examples:
Map Constraints
Syntax:map<keytype, valuetype>
Examples:
Schema Language
Schema Definition
Syntax:@open- Accept unknown fields@packed- Use compact encoding@deprecated- Mark as deprecated
Example Schema
Field Definitions
Required fields:Type References
Primitive references:Validation
Type Validation
Type validation ensures values match their declared types:Constraint Validation
Constraints are checked during validation: Integer bounds:Strict vs Loose Validation
Loose validation:- Unknown fields in
@openstructs: warning - Missing optional fields: allowed
- Type coercion: allowed (e.g., int to float)
- Unknown fields: error (even in
@openstructs) - All declared fields must be present
- No type coercion
Schema Evolution
Versioning
Schemas support versioning for backward compatibility:Compatibility Rules
Backward compatible changes:- Add optional fields
- Add default values
- Make required field optional
- Expand enum values
- Relax constraints (widen ranges)
- Remove fields
- Change field types
- Add required fields
- Remove enum values
- Tighten constraints
Migration Strategies
Version negotiation:Type System Grammar
BNF Definition
Conformance
Implementation Requirements
A conformant type system implementation MUST:- Support all primitive types
- Support all collection types
- Enforce type constraints during validation
- Support schema versioning
- Provide strict and loose validation modes
- Handle unknown fields according to
@openannotation - Validate nested types recursively
- Report validation errors with field paths
Cross-Language Compatibility
All implementations MUST:- Accept identical valid inputs
- Reject identical invalid inputs
- Report compatible error messages
- Support the same constraint syntax
Related Documentation
- Loose Mode Specification - Canonical rules and JSON bridge
- GS1 Protocol - Stream framing and state verification