Type System Overview
Leo is a statically-typed language where every variable, function parameter, and expression has a known type at compile time. The type system ensures safety and correctness in zero-knowledge applications.Primitive Types
Integer Types
Leo supports both unsigned and signed integers with various bit widths:- Unsigned
- Signed
Integer literals can include underscores for readability:
1_000_000u64 is equivalent to 1000000u64.Address Type
Theaddress type represents Aleo account addresses:
.aleo domain syntax:
Boolean Type
Thebool type represents logical true or false values:
Field Type
Thefield type represents elements in a finite field, used for cryptographic operations:
Group Type
Thegroup type represents elliptic curve points:
Scalar Type
Thescalar type represents scalar values for elliptic curve operations:
Signature Type
Thesignature type represents cryptographic signatures:
Composite Types
Structs
Structs define custom data types with named fields:Records
Records are special structs with anowner field that represent owned assets:
Arrays
Arrays are fixed-size collections of elements of the same type:Tuples
Tuples group multiple values of different types:Special Types
Unit Type
The unit type() represents the absence of a value:
Optional Types
Optional types represent values that may or may not exist:Mapping Types
Mappings define the key-value structure for on-chain storage:Future Types
TheFinal type represents deferred on-chain computation:
Type Inference
Leo can infer types in many contexts:While type inference is supported, explicit type annotations improve code readability and catch errors earlier.
Type Casting
Leo supports explicit type casting using theas operator:
Type Compatibility
Numeric Literals
Unsuffixed numeric literals are treated asu32 by default:
Struct Compatibility
Structs are nominally typed - two structs with identical fields but different names are not compatible:Default Values
Leo provides zero values for all types:Numeric Radix
Integer literals support multiple bases:Best Practices
1. Choose Appropriate Integer Sizes
2. Use Explicit Types for Clarity
3. Document Custom Types
Next Steps
Operators
Learn about type operations
Records
Work with owned data
Statements
Use types in statements
Functions
Define typed functions