Types
Scalars
Scalar types follow the Wasm IT notation.
Unsigned numbers:
u8,u16,u32,u64Signed numbers:
i8,i16,i32,i64Floats:
f32,f64Boolean:
boolString:
stringRecords (product type): see below
Arrays: see Collection Types below
Literals
You can pass booleans (true, false), numbers, double-quoted strings as literals.
Products
data ProductName:
field_name: string
data OtherProduct:
product: ProductName
flag: boolFields are accessible with the dot operator . , e.g. product.field.
Collection Types
Aqua has three different types with variable length, denoted by quantifiers [], *, and ?.
Immutable collection with 0..N values: []
Immutable collection with 0 or 1 value: ?
Appendable collection with 0..N values: *
Any data type can be prepended with a quantifier, e.g. *u32, [][]string, ?ProductType are all correct type specifications.
You can access a distinct value of a collection with ! operator, optionally followed by an index.
It is possible to fill any collection with an empty one using nil.
Examples:
Arrow Types
Every function has an arrow type that maps a list of input types to an optional output type.
It can be denoted as: Type1, Type2 -> Result
In the type definition, the absence of a result is denoted with (), e.g., string -> ()
The absence of arguments is denoted -> ().That is, this mapping takes no argument and has no return type.
Note that there's no Unit type in Aqua: you cannot assign a non-existing result to a value.
Type Alias
For convenience, you can alias a type:
Type Variance
Aqua is made for composing data on the open network. That means that you want to compose things if they do compose, even if you don't control its source code.
Therefore Aqua follows the structural typing paradigm: if a type contains all the expected data, then it fits. For example, you can pass u8 in place of u16 or i16. Or ?bool in place of []bool. Or *string instead of ?string or []string. The same holds for products.
For arrow types, Aqua checks the variance on arguments and contravariance on the return type.
Arrow type A: D -> C is a subtype of A1: D1 -> C1, if D1 is a subtype of D and C is a subtype of C1.
Type Of A Service And A File
A service type is a product of arrows.
The file is a product of all defined constants and functions (treated as arrows). Type definitions in the file do not go to the file type.
See Imports and Exports for module declarations.
Last updated
Was this helpful?
