Type System
Dryft features a static type system that verifies type correctness at compile time. The type system is stack-based, tracking the types of values on the stack as your program executes.Built-in Types
Dryft has three fundamental value types:Number
Integer numbers (signed):Text
String literals:Binary
Boolean values for logic and conditionals:Type Inference
The compiler automatically tracks types on the stack. When you push a value, its type is known:Function Type Signatures
Functions consume input types from the stack and produce output types:Notation
Type signatures use the format:(inputs -> outputs)
- Takes two integers from the stack
- Returns one boolean
Multiple Outputs
No Inputs or Outputs
Type Checking
The compiler enforces type safety throughout your program:Arithmetic Operations
Arithmetic operators requireNumber types:
Comparison Operations
Comparisons produceBinary (boolean) results:
Logical Operations
Logical operations work onBinary types:
Type Footprint
Blocks must have a balanced type footprint - they should return the same types they consume:Type Errors
The compiler catches type mismatches:Variables and Types
Variables are typed when declared:Method Types
Functions and actions can have complex type signatures:Type System and Linear Types
Dryft’s type system works in conjunction with its linear type system. Each value must be used exactly once, ensuring:- No memory leaks
- No use-after-free
- Explicit resource management
Benefits of Static Typing
- Early Error Detection: Catch mistakes at compile time
- Documentation: Type signatures document function behavior
- Optimization: Compiler can optimize based on type information
- Safety: Prevents entire classes of runtime errors
Type System Features
Dryft’s type system can be disabled with a compilation flag (
typesystem feature), but this is not recommended for production code.