Types

Calor has a simple type system with primitives, optionals, and results.


Primitive Types

CalorDescriptionC#Range
i3232-bit signed integerint-2^31 to 2^31-1
i6464-bit signed integerlong-2^63 to 2^63-1
f3232-bit floating pointfloat+/-3.4 x 10^38
f6464-bit floating pointdouble+/-1.8 x 10^308
strStringstringUTF-16 text
boolBooleanbooltrue or false
voidNo valuevoid(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 active

Output Types

Plain Text
§O{i32}             // returns int
§O{str}             // returns string
§O{void}            // returns nothing

Option 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 value

Example

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) - failure

Common 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 U

Examples

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 T

Nested 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}
PartDescription
nameVariable name for the list
elementTypeType 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}
PartDescription
nameVariable name for the dictionary
keyTypeType of keys
valueTypeType of values
§KVKey-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

OperationSyntaxDescription
Add to list/set§PUSH{coll} valuecollection.Add(value)
Set dictionary entry§PUT{dict} key valuedict[key] = value
Set list index§SETIDX{list} idx valuelist[index] = value
Insert at index§C{list.Insert} §A idx §A val §/Clist.Insert(idx, val)
Remove element§C{coll.Remove} §A val §/Ccollection.Remove(val)
Clear collection§C{coll.Clear} §/Ccollection.Clear()

Example:

Plain Text
§PUSH{numbers} 4              // numbers.Add(4)
§PUT{ages} "charlie" 35       // ages["charlie"] = 35
§SETIDX{numbers} 0 10         // numbers[0] = 10

Collection Queries

QuerySyntaxReturns
Contains element§HAS{coll} valuebool
Contains key§HAS{dict} §KEY keybool
Contains value§HAS{dict} §VAL valuebool
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

OperationValid Types
Arithmetic (+, -, *, /)Numeric (i32, i64, f32, f64)
Modulo (%)Integer (i32, i64)
Comparison (<, >, etc.)Numeric, str
Equality (==, !=)Any matching types
Logical (&&, ||)bool

Literals

TypeLiteral Examples
i3242, -17, 0
i6442L, -17L
f323.14f
f643.14, 2.718
str"hello", "world"
booltrue, false

Next