Basic Types
The type system of the Alia language falls into two major categories: Code and Value.
1. Code Types
Code represents code and is one of the most core types in Alia, used to define syntax structures.
Subtypes
- Key: A keyword, a single lexical unit
- Keys: A multi-part keyword, composed of multiple lexical units
- The symbol
<>denotes a parameter within a multi-part keyword - A multi-part keyword can be matched up to the nearest enclosing definition separator
- For example, in
<Keys keys> to <Stack stack>, the separator "to" distinguishes where keys and stack match
- The symbol
- Variable: A variable reference, an expression that can resolve to any variable, member access, or index access
- At runtime it resolves to the corresponding variable value, object member value, or array element value
- The following forms are supported:
- Simple variable:
x - Member access:
obj.property - Index access:
arr[0],obj['key']
- Simple variable:
- Commonly used in scenarios that require dynamically obtaining variables or properties
Example
alias whenTrue <Boolean condition> <Stack stack> -> { if condition { call stack.run } }
2. Value Types
Value represents content and is the type used in Alia to store data.
Value Operation Restrictions (Static Typing)
An unreduced <Value> triggers a type error (TYPE_VALUE_OPERATION) when participating in the following operations; it must first be narrowed via typeOf / Ok / as:
- Arithmetic, logical, and unary (
!,-) operations - Conditions of
if/while/forand targets ofeach - Indexing
value[...]and property accessvalue.prop - Comparison with another non-literal value
Legal dynamic bridges (exceptions):
- Comparison with literals:
value == 42,value == 'text' call value.valueOf: explicitly unwraps the underlying value and returns the original type<Dynamic>bypasses checks entirely and propagates asDynamic
alias process <Value data> -> Value {
if typeOf data == 'Number' {
data * 2
} else {
data
}
}
Subtypes
- String: string
- Number: number
- BigInt: arbitrary-precision integer
- Arithmetic and comparisons accept BigInt operands only; mixing with Number/String raises immediately — convert explicitly with
as BigIntfirst /and%truncate toward zero (C++ semantics):7n / 2nis3n,-7n % 3nis-1ntypeOf 123nreturns'BigInt'
- Arithmetic and comparisons accept BigInt operands only; mixing with Number/String raises immediately — convert explicitly with
- Boolean: boolean
- Object: object
Example
~ String
const str = 'Hello'
~ Number
const num = 42
~ Arbitrary-precision integer (an integer literal suffixed with n)
const big = 9999999999999999999999999999999999999999n
const product = big * big
print product
~ Boolean
const bool = true
~ Object
const obj = *[ name: 'Alia', version: 0.1 ]
3. Object Types
Object is the composite type in Alia, including the following subtypes:
Subtypes
| Type | Description |
|---|---|
| Object String | String object |
| Object Number | Number object |
| Object BigInt | Arbitrary-precision integer object |
| Object Boolean | Boolean object |
| Object Array | Array |
| Object Object | Object |
| Object Stack | Stack |
| Object Alias | Keyword alias |
| Object Error | Error |
| Object Sheet | Two-dimensional array table |
| Object Date | Date and time |
| Object RegExp | Regular expression |
| Object Channel | Channel |
| Object Color | Color |
| Object ColoredString | Colored string |
Object Syntax
| Syntax | Description |
|---|---|
*[ <Key key>: <Value value>, ... ] | Defines an object |
[ <Value value>, ... ] | Defines an array |
*{ ... } | Defines a stack with a new context |
{ ... } | Defines a stack that uses the original context |
mut *{ ... } | Defines a mutable stack with a new context |
mut { ... } | Defines a mutable stack that uses the original context |
Multi-parameter built-in methods use auxiliary keywords to separate parameters, such as to, with, at, or, limit, and, in, from, named, keyed, returning.
Example
~ Array
const arr = [1, 2, 3, 4, 5]
~ Object
const obj = *[ name: 'Alia', version: 0.1 ]
~ Stack (new context)
const stack = *{
let x = 1
print x
}
~ Stack (original context)
const stack2 = { print x }
~ Mutable stack (new context)
const mutStack = mut *{
if Has 'count' { count = count + 1 } else { let count = 1 }
count
}
~ Mutable stack (original context)
const mutStack2 = mut {
let val = 10
val
}
~ Access object properties
print obj.name
print arr[0]
print call stack.run
print call mutStack.run ~ Outputs 1
print call mutStack.run ~ Outputs 2
Delimiters
Statements in Alia are terminated by newlines:
\n: newline character
Statements are separated by newline characters; the standard paradigm uses newlines as statement terminators.
Token Separators
: space
Spaces separate keywords and parameters and are the basic separator during lexical analysis.
Escape Characters
'\': escapes the single character that follows'${}': escapes all characters within
Basic Characters (Literals)
| Category | Symbols | Description |
|---|---|---|
| Arithmetic | + - * / % | Basic mathematical operations |
| Logical | & | ! | Logical AND, OR, NOT |
| Conditional branch | ? : | Ternary operator |
| Null coalescing | ?? | Null coalescing |
| Size comparison | > < >= <= != == | Comparison operators |
| Order of operations | ( ) | Parentheses |
| Strings | ' " | String delimiters |
| Keywords | ` | Keyword delimiter |
| String concatenation | .. | String addition |
| Numbers | 0-9 | Digit characters |
| BigInt suffix | n | Append n to an integer for an arbitrary-precision integer, e.g. 123n |
Type Checking System
Alia's type checking runs in the Check phase, after Astify and before Interpret/Compile.
Example Code
~ Type examples
const str: String = 'Hello'
const num: Number = 42
const bool: Boolean = true
const arr: Array = [1, 2, 3]
const obj: Object = *[ name: 'Alia' ]
~ Type checking
if typeOf str == 'String' { print 'str is a String' }
if typeOf num == 'Number' { print 'num is a Number' }
if Ok str { print str.length }
assert (Ok str)
const numFromStr = '42' as Number