Types
Calor has a simple type system with primitives, optionals, and results.
Primitive Types
| Calor | Description | C# | Range |
|---|---|---|---|
i32 | 32-bit signed integer | int | -2^31 to 2^31-1 |
i64 | 64-bit signed integer | long | -2^63 to 2^63-1 |
f32 | 32-bit floating point | float | +/-3.4 x 10^38 |
f64 | 64-bit floating point | double | +/-1.8 x 10^308 |
str | String | string | UTF-16 text |
bool | Boolean | bool | true or false |
void | No value | void | (return type only) |
Usage in Declarations
Input Parameters
Plain Text
§I{i32:count} // int count
§I{str:name} // string name
§I{f64:price} // double price
§I{bool:active} // bool activeOutput Types
Plain Text
§O{i32} // returns int
§O{str} // returns string
§O{void} // returns nothingOption Type (?T)
Options represent values that may be absent.
Syntax
Plain Text
?T // Option of T (may be null)Examples
Plain Text
§F{f001:Find:pub}
§I{str:key}
§O{?str} // might return a string, might return nothing
// ...
§/F{f001}
§F{f002:Process:pub}
§I{?i32:maybeValue} // accepts null
§O{void}
// ...
§/F{f002}Creating Option Values
Plain Text
§SM value // Some(value) - has a value
§NN // None - no valueExample
Plain Text
§F{f001:FindUser:pub}
§I{i32:id}
§O{?User}
§IF{if1} (== id 0)
§R §NN
§EL
§R §SM user
§/I{if1}
§/F{f001}Result Type (T!E)
Results represent computations that may fail.
Syntax
Plain Text
T!E // Result: either T (success) or E (error)Examples
Plain Text
§F{f001:Divide:pub}
§I{i32:a}
§I{i32:b}
§O{i32!str} // returns int on success, string error on failure
§IF{if1} (== b 0)
§R §ERR "Division by zero"
§EL
§R §OK (/ a b)
§/I{if1}
§/F{f001}Creating Result Values
Plain Text
§OK value // Ok(value) - success
§ERR "message" // Err(message) - failureCommon Patterns
Parse integer:
Plain Text
§F{f001:ParseInt:pub}
§I{str:text}
§O{i32!str}
// ...implementation
§/F{f001}File read:
Plain Text
§F{f001:ReadFile:pub}
§I{str:path}
§O{str!str}
§E{fs:r}
// ...implementation
§/F{f001}Generic Types
Generic types use angle bracket syntax inline.
Syntax
Plain Text
List<T> // List of T
Dictionary<K, V> // Dictionary with key K and value V
IEnumerable<T> // Enumerable of T
Func<T, U> // Function from T to UExamples
Plain Text
§I{List<i32>:numbers} // List<int> parameter
§I{Dictionary<str, i32>:scores} // Dictionary<string, int>
§O{IEnumerable<str>} // Returns IEnumerable<string>
§FLD{HashSet<T>:_items:pri} // Generic field with type parameter TNested Generic Types
Generic types can be nested.
Plain Text
§I{Dictionary<str, List<i32>>:data} // Dictionary<string, List<int>>
§O{List<Tuple<str, i32>>} // List<(string, int)>Type Parameters
When defining generic functions or classes, type parameters (like T, U) can be used as types.
Plain Text
§F{f001:First:pub}<T>
§I{List<T>:items}
§O{T}
§R items[0]
§/F{f001}See Structure Tags - Generics for more on defining generic functions and classes.
Collection Types
Calor provides built-in syntax for creating and manipulating collections with type-safe operations.
List Creation
Plain Text
§LIST{name:elementType}
element1
element2
§/LIST{name}| Part | Description |
|---|---|
name | Variable name for the list |
elementType | Type of elements (i32, str, etc.) |
Example:
Plain Text
§LIST{numbers:i32}
1
2
3
§/LIST{numbers}Dictionary Creation
Plain Text
§DICT{name:keyType:valueType}
§KV key1 value1
§KV key2 value2
§/DICT{name}| Part | Description |
|---|---|
name | Variable name for the dictionary |
keyType | Type of keys |
valueType | Type of values |
§KV | Key-value pair entry |
Example:
Plain Text
§DICT{ages:str:i32}
§KV "alice" 30
§KV "bob" 25
§/DICT{ages}HashSet Creation
Plain Text
§HSET{name:elementType}
element1
element2
§/HSET{name}Example:
Plain Text
§HSET{tags:str}
"urgent"
"review"
§/HSET{tags}Collection Operations
| Operation | Syntax | Description |
|---|---|---|
| Add to list/set | §PUSH{coll} value | collection.Add(value) |
| Set dictionary entry | §PUT{dict} key value | dict[key] = value |
| Set list index | §SETIDX{list} idx value | list[index] = value |
| Insert at index | §C{list.Insert} §A idx §A val §/C | list.Insert(idx, val) |
| Remove element | §C{coll.Remove} §A val §/C | collection.Remove(val) |
| Clear collection | §C{coll.Clear} §/C | collection.Clear() |
Example:
Plain Text
§PUSH{numbers} 4 // numbers.Add(4)
§PUT{ages} "charlie" 35 // ages["charlie"] = 35
§SETIDX{numbers} 0 10 // numbers[0] = 10Collection Queries
| Query | Syntax | Returns |
|---|---|---|
| Contains element | §HAS{coll} value | bool |
| Contains key | §HAS{dict} §KEY key | bool |
| Contains value | §HAS{dict} §VAL value | bool |
| Collection count | §CNT{coll} | i32 |
Example:
Plain Text
§IF{if1} §HAS{numbers} 5 → §P "Found 5"
§/I{if1}
§B{count} §CNT{ages}Type Annotations in Contracts
Types matter in contracts for proper comparisons:
Plain Text
§F{f001:Clamp:pub}
§I{i32:value}
§I{i32:min}
§I{i32:max}
§O{i32}
§Q (<= min max) // Requires: min <= max
§S (>= result min) // Ensures: result >= min
§S (<= result max) // Ensures: result <= max
// ...
§/F{f001}Type Compatibility
| Operation | Valid Types |
|---|---|
Arithmetic (+, -, *, /) | Numeric (i32, i64, f32, f64) |
Modulo (%) | Integer (i32, i64) |
Comparison (<, >, etc.) | Numeric, str |
Equality (==, !=) | Any matching types |
Logical (&&, ||) | bool |
Literals
| Type | Literal Examples |
|---|---|
i32 | 42, -17, 0 |
i64 | 42L, -17L |
f32 | 3.14f |
f64 | 3.14, 2.718 |
str | "hello", "world" |
bool | true, false |
Next
- Expressions - Operators and expressions